I am new to javascript, recently I am studying javascript array and object.
if I have a object
const initialValue = {
a: 30,
b: 40,
c: 50
}
const initialValueKey = Object.keys(initialValue)
const [, , , ...value] = initialValueKey;
I wonder what is this [, , , ...value] expression, I know ...is spread operator, but i'm not sure what the value of [, , , ...value] here.
2 Answers 2
It is a way to retrieve "other values", or retrieving the values and skipping the first n.
Here's an example:
const obj = {
a: 1,
b: 2,
c: 3,
d: 4,
e: 5
};
const data = Object.keys(obj);
const [,,, ...values] = data;
console.log(values);
answered Jul 15, 2020 at 3:48
yqlim
7,1273 gold badges21 silver badges44 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
This is a way to assign the variables to arrays. the two commas in this example skipsthe first 2 elements
const initialValue = {
a: 30,
b: 40,
c: 50,
d: 70
}
const initialValueKey = Object.keys(initialValue)
const [, , ...value] = initialValueKey;
console.log(value);
answered Jul 15, 2020 at 4:57
Sachintha Nayanajith
7315 silver badges12 bronze badges
Comments
lang-js
value. Try making yourinitialValuewith more properties to see the differenceconst value = initialValueKey.slice(3);