This question already has answers here:
How to destructure object properties with key names that are invalid variable names?
(3 answers)
How to use special characters (like hyphen) in destructuring assignment syntax? [duplicate]
(2 answers)
Closed 7 months ago.
I have an object with this data structure returned by api:
const obj = {customer:id: '123'}
How should I destruct this object? Thanks
This question already has answers here:
Javascript - Getting and setting properties on primitives implicitly creates object wrappers
(3 answers)
How is almost everything in Javascript an object?
(6 answers)
adding properties to primitive data types other than Array
(2 answers)
Closed 1 year ago.
I am new to JS, and JS syntax is definitely confusing to me as I'm used to other languages instead.
const x = 5;
x.yy = 3;
console.log(x.yy); // undefined
How is x.yy = 3; a valid syntax?
and why is x.yy undefined when x.yy =3; took in place?
This question already has answers here:
How to determine equality for two JavaScript objects?
(82 answers)
How do I check if an array includes a value in JavaScript?
(60 answers)
Closed 3 years ago.
IndexOf cannot find my object. Here is the JsFiddle
let a = [{}]
console.log(a.indexOf({}))
This question already has answers here:
What’s the difference between “{}” and “[]” while declaring a JavaScript array?
(8 answers)
Closed 4 years ago.
The point of confusion is - when we check the type of array or object using typeof get the return value as Object. So what's the main difference between them.
You can check using constructor.name
const myArr = []
const myObj = {}
console.log(`myArr is an ${myArr.constructor.name}`)
console.log(`my Obj is an ${myObj.constructor.name}`)
This question already has answers here:
Self-references in object literals / initializers
(30 answers)
Can a JavaScript object property refer to another property of the same object? [duplicate]
(2 answers)
How do I reference the same Object's properties during its creation? [duplicate]
(5 answers)
How can a JavaScript object refer to values in itself? [duplicate]
(8 answers)
Can I reference other properties during object declaration in JavaScript? [duplicate]
(7 answers)
Closed 5 years ago.
var fighters = ['johnjones', 'rondarousey', 'connormcgregor', 'chuckliddel', 'demetriusjohnson'];
var warriors = {
wrestlers: ['randysavage', 'hulkhogan', 'ultimatewarrior', 'jakethesnake', 'milliondollarman'],
stable: [fighters, warriors.wrestlers]
}
I believe I can reference fighters from stable, but can I reference wrestlers from stable? In other words, how do I reference a key value pair from a later key value pair within the warriors object. Thank you for any and all help!
You cannot do that until the variable warriors is initialized. The only way is to wait and assign in the next line:
var warriors = {
wrestlers: ['randysavage', 'hulkhogan', 'ultimatewarrior', 'jakethesnake', 'milliondollarman'],
}
warriors.stable = [fighters, warriors.wrestlers]
Or use some kind of weird initialization like the one described here. Or use function constructor.