2

I have an array of objects with binary Files like this

[{item: File},{item: File},{item: File}]

and i need to add new key/value to every obj. I tried doing it with mapping an array and concatenating new property 'description' with existing 'name':

arr.map((el) => ({ ...el, description: '' }))

so it should look like this:

[{item: File, description: ''},{item: File, description: ''},{item: File, description: ''}].

But when i try to do this, it only returns a description without name:

pic

2
  • 1
    Are you sure your original objects have name properties to begin with? What you have showed should work. Please provide a minimal reproducible example. Commented Jun 24, 2020 at 9:25
  • My bad. Initially i tried to add description to object with binary File. Edited it Commented Jun 24, 2020 at 9:41

1 Answer 1

6

maybe you forgot to assign 'map'

returned value to your object. lets do it:

let arr = [{name: '1'},{name: '2'},{name: '3'}]
arr = arr.map( item => ({ ...item, description:'' }) )
console.log(arr)

result is :

0: {name: "1", description: ""}
1: {name: "2", description: ""}
2: {name: "3", description: ""}
Sign up to request clarification or add additional context in comments.

1 Comment

Well, the image shows that the object has a description property...

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.