I have an array with this values:
0:
code: "fb"
description: "Not relevant text."
did: 1
name: "Some random name"
sortOrder: 1
1:
code: "fr"
description: "Not relevant text."
did: 2
name: "Some random name"
sortOrder: 2
When i map the array like this:
values: this.stackOverflowExample.map(v => v.code).push(null)
And push a null code to the set, it sets all values to null
The output I want:
values: [
0: 'fb'
1: 'fr'
2: null ]
The output I got:
values: 3
How do I add values to the array this.stackOverflowExample
which is mapped by code, without affecting the other values?
Array.prototype.pushmethod doesn't return the array it is called on. Rather, it returns the length of the array after adding the element. Either use a temporary variable, as inconst a = this.stackOverflowExample.map(v => v.code).push(null);values: a` or to add the element using a method that returns the array such, i.e.Array.prototype.concat, as invalues: this.stackOverflowExample.map(v => v.code).concat([null])concatmethod for thearray, it does exactly what I wanted to achive.