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

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -