Unwanted undefined key in object
Starting from an array like this:
And an array like thisWhat's the best way to obtain an array like this?
Current solution https://jsfiddle.net/n00bCod3r/jdc1hu5p/
However, I get an undefined key and I don't understand why
6 Replies
there's no field definition for block_state
that is triggering your null deference operator, which is returning
undefined
instead of throwing an error. You could do a similar check like you do on the value and use a ternary operator to set a default value other than undefined
hmm i'll try
The only solution that came to me, what did you have in mind?
this way, each key is represented, even if it's not in the mapping array, just with the original value instead of the translated one
I don't want the original key tho, if it's not present
The other keys are added
That's why I added the comment in my first message, I apologise if this wasn't clear
My solution work even if it's not the best
then use this instead of the map function
you can add some
newKey === undefined
and reuse your own value ternary if you want, I was just being lazy 🙂ok, ty