-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?

Sophia
  • 9
  • 4

1 Answers1

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)
JaivBhup
  • 792
  • 4
  • 7