How do you work with JSON with unique keys?

This question already has an answer here:

  • How to list the properties of a JavaScript object? 16 answers

  • You can iterate through the keys using the for...in clause.

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in

    You can discover if the field belongs to the object direct, as opposed to part of the prototype using hasOwnProperty.

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty

    If you're using a library like Lodash or underscore you can use the _.each function to iterate through the object keys and properties, or the _.keys to return all the keys in the object.

    http://lodash.com/docs#keys

    Beyond this, if you have a specific use case, you'd have to elaborate on your particular problem in greater detail.

    链接地址: http://www.djcxy.com/p/27360.html

    上一篇: JavaScript的

    下一篇: 你如何使用JSON与唯一密钥一起工作?