i have file contains json array of tasks:
currently file contains:
[ {"task":"hey", "checked":"0", "data1":"", "data2":"", "data3":""}, {"task":"there", "checked":"0", "data1":"jiojoi", "data2":"", "data3":""} ] i want isolate signle task use following code:
var taskexp = new regexp('{"task":"' + taskname + '",.*"}', ''); // task var task = taskexp.exec(text); in specific case, if taskname = "hey", returns whole string. (2 tasks).
if taskname = "there", it's ok.
why? in advance.
it's bad idea use regexes filter out properties of json string.
parse object (/array), use filter, instead.
assuming text json string:
var dataarray = json.parse(text), taskname = "sometaskname"; var result = dataarray.filter(function(item){ return item.task === taskname; }); then, result array of matching tasks.
Comments
Post a Comment