Gets the key "key" of the object and gets the key "key" and the value of the array separately

Source: Internet
Author: User

First, say the object, how to get Key "key";


var obj={          Name: "Websong",          qq:289483936    }


To get the key "name" and "QQ" for this obj object, you need to use the keys method of the built-in object, the code is as follows:

Object.keys (obj). ForEach (function (key,i,v) {            console.log (key)            Console.log ("---------")            Console.log ( i);            Console.log ("---------")            Console.log (v)        })   


This method can output the key of the object obj as an array, and then we get it in a circular way.

Second, get the key and value of the array object

var arr=[{a:3},{b:4},{qqque:535880373}];


The truth is the same, the only thing is to loop the array first, the code is as follows:

Arr.foreach ((v,i) =>{                               Object.keys (v). ForEach (v=>{                console.log (v)//takes the key                Console.log (arr[i][v ])//(Value of            })        })


OK, here's the end of the content. If I can help you, I am very happy.

Gets the key "key" of the object and gets the key "key" and the value of the array separately

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.