-1

You must create a function called arrayOfObjects that receives a number as a parameter and returns an array of objects that have a property called value that contains the value of the number and its predecessors.

example

ArrayOfObjects(3) 

should return:

[{value: 1}, {value: 2}, {value: 3}] 

my code

function arrObj(number){
  let newArray = [];
  for(let i = 0;i<number; i++){
    newArray.push(number.object)
  }
  console.log(newArray)
}

arrObj(5)

I'm new with objects, can someone help me?

0

1 Answer 1

0

To insert into newArray you need to add an object with a key of value and value of the incremental index. Here is a snippet that would do that.

function arrObj(number){
  let newArray = [];
  for(let i = 0;i<number; i++){
    // Push {value:number}
    newArray.push({value:i+1})
  }
  console.log(newArray)
}

arrObj(5)

Sign up to request clarification or add additional context in comments.

2 Comments

Please provide some context and description to the answer.
I was close, thank you very much!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.