I have an array like this:
var arr = [];
arr = [['red', 685], ['green', 210], ['blue', 65]];
Also I have two variables:
var color = 'blue';
var number = 21;
All I'm trying to do is checking the first item of each nested array of arr and then either update the second item of it or make a new array for it.
Here is some examples:
Input:
var color = 'blue';
var number = 21;
Expected output:
arr = [['red', 685], ['green', 210], ['blue', 21]];
Input:
var color = 'yellow';
var number = 245;
Expected output:
arr = [['red', 685], ['green', 210], ['blue', 21], ['yellow', 245]];
Here is what I've tried so far:
if ( !arr.includes(color) ) {
arr.push([color, number]);
} else {
arr[color] = time;
}
But !arr.includes(color) condition is wrong. Because each item of arr is also an array. Anyway, how can I use includes() function on the first item of nested arrays?