javascript - how to get Index of json object -


i have json string as:

  var str="[{ 'label': 'month'},{ label: 'within'},{ label: 'from'},          { label: 'where'},]"; 

i converted json objects as:

      var tagstring = eval(str);  

i want index of month without loop

is there better way index of object without using loops?

thanks in advance!

if labels, change structure this, it's "an array of labels" which, in opinion, more proper.

var str = '["month","within","from","where"]'; 

then parse them json.parse, or since using jquery, $.parsejson work on more browsers:

var labels = json.parse(str); 

labels should array, can use array.indexof.

var index = labels.indexof('month'); 

it's es5 , modern browsers support it. older browsers, you need polyfill unfortunately... uses loop.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -