console.log(obj[key]))" statement in react to traverse the object."/> console.log(obj[key]))" statement in react to traverse the object.">

Home >Web Front-end >JS Tutorial >How to traverse objects in react

How to traverse objects in react

藏色散人
藏色散人Original
2020-12-18 11:26:316596browse

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.

How to traverse objects in react

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn