jquery selectors for plain javascript objects instead of DOM elements

后端 未结 4 955
遇见更好的自我
遇见更好的自我 2021-02-06 11:05

I\'ve just started using jquery and I\'m really enjoying using selectors. It occurs to me that the idiom would be a very nice way to traverse object trees (e.g., JSON query resu

4条回答
  •  轮回少年
    2021-02-06 11:53

    The array object has some methods that you can use:

    last = obj.child.baz.slice(-1)[0];
    

    Some other examples:

    first = obj.child.baz.slice(0,1)[0];
    allExceptFirst = obj.child.baz.slice(1);
    allExceptLast = obj.child.baz.(0,-1);
    

提交回复
热议问题