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.

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);

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);

Comments

Your Answer

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.