Method to traverse objects in react: first open the corresponding code file; then use "Object.keys(obj).map(key => console.log(obj[key]))" in react statement to traverse the object.
The operating environment of this tutorial: windows7 system, react17.0.1 version, this method is suitable for all brands of computers.
Related recommendations: react video tutorial
react traversal object
Example:
const obj = { channel: “wevmvmklskdosll12k;0”, index:0 }; Object.keys(obj).map(key => console.log(obj[key]));
has ES6 Syntax, must be used with Babel...
Object.keys() method will return an array consisting of the enumerable properties of a given object. The order of the property names in the array and the use of for...in loop The order returned when traversing the object is the same (the main difference between the two is that a for-in loop also enumerates the properties on its prototype chain).
The map() method returns a new array, and the elements in the array are the values of the original array elements after calling the function.
The map() method processes elements sequentially in the order of the original array elements.
The above is the detailed content of How to traverse objects in react. For more information, please follow other related articles on the PHP Chinese website!