javascript - Find similar items in an object -
i have object looks so:
{ title: "test", subtitle: "test", "list-item-1": "this item 1", "list-item-2": "this item 2", "list-item-3": "this item 3" }
i want find keys in object end -1
, or -
numerical value. , group of in way can access them calling "if item has -1
@ end of it, find other items have same first part (list-item
in case) , save them own array or variable.
how go this?
one simple way harvest properties use built in methods keys(), filter(), , test():
var obj={ title: "test", subtitle: "test", "list-item-1": "this item 1", "list-item-2": "this item 2", "list-item-3": "this item 3", }; var arrok=object.keys(obj).filter(/./.test, /list-item-\d+$/); alert(arrok); // shows: "list-item-1,list-item-2,list-item-3"
Comments
Post a Comment