1

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.

asked Jul 15, 2020 at 3:44
2
  • It's skipping the first 3 values and assigning the rest of the array to value. Try making your initialValue with more properties to see the difference Commented Jul 15, 2020 at 3:48
  • 1
    it's a complicated way to write const value = initialValueKey.slice(3); Commented Jul 15, 2020 at 3:48

2 Answers 2

3

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
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.