“JavaScript Object First Key” Kode Jawaban

cara mendapatkan kunci pertama dalam objek n di javascript

var obj = { "a" : 1, "b" : 2, "c" : 3};
alert(Object.keys(obj)[0]);
// alerts "a"
let objLength = Object.keys(obj).length
console.log(objLength)
// Logs 3 as "obj" has 3 keys
var objValue = Object.values(obj)[0]
console.log(objValue)
// Logs "1" as the value of the first key(a) is "1"
Fierce Ferret

JS Dapatkan Nilai Objek Pertama

var obj = { first: 'someVal' };
obj[Object.keys(obj)[0]]; //returns 'someVal'
GutoTrosla

JavaScript Object First Key

var person = {"name":"Steve","age":43};
var firstKeyValue = person[Object.keys(person)[0]]; //"Steve"
Grepper

Dapatkan JavaScript Kunci Objek Pertama

var example = {
    foo1: { /* stuff1 */},
    foo2: { /* stuff2 */},
    foo3: { /* stuff3 */}
};

let [first] = Object.keys(example)

console.log(first)
Ntiyiso-Rikhotso

Jawaban yang mirip dengan “JavaScript Object First Key”

Pertanyaan yang mirip dengan “JavaScript Object First Key”

Lebih banyak jawaban terkait untuk “JavaScript Object First Key” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya