Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

2 dimensional array index of element value

let a = [ [ 'bird' ], [ 'cat' ], [ 'dog' ], [ 'cow' ], [ 'bird' ] ];
let b = _.findIndex(a, function(el) { return el[0] == 'cow'; });
console.log(b);//answer is 3
Comment

2 dimensional array index of element value


var arr = [[2,3],[5,8],[1,1],[0,9],[5,7]];
var coor1 = [0, 9];
var coor2 = [1, 2];

function isItemInArray(array, item) {
    for (var i = 0; i < array.length; i++) {
        // This if statement depends on the format of your array
        if (array[i][0] == item[0] && array[i][1] == item[1]) {
            return true;   // Found it
        }
    }
    return false;   // Not found
}

// Test coor1
console.log("Is it in there? [0, 9]", isItemInArray(arr, coor1));   // True

// Test coor2
console.log("Is it in there? [1, 2]", isItemInArray(arr, coor2));   // False

// Then
if (!isItemInArray(arr, [x, y])) {
   arr.push([x, y]);
}

Comment

PREVIOUS NEXT
Code Example
Javascript :: angular2-tree-diagram 
Javascript :: how fetch multiple data in javascript react 
Javascript :: js get location params 
Javascript :: change height of div with scroll in javascript 
Javascript :: javascript settimeout lambda function 
Javascript :: react native bottom sheet 
Javascript :: merge two singly linked lists 
Javascript :: add two empty arrays javascript 
Javascript :: mui date picker 
Javascript :: how to draw circle in javascript 
Javascript :: drupal 8 webform insert node twig value 
Javascript :: await javascript 
Javascript :: rails json schema validation 
Javascript :: create javascript map 
Javascript :: chart js &php 
Javascript :: dropdown hide 
Javascript :: schema knex.js 
Javascript :: get width of html photo 
Javascript :: dynamodb count items node 
Javascript :: faire un tableau en javascript 
Javascript :: javascript regex insert string 
Javascript :: js index to index 
Javascript :: FTP download local file 
Javascript :: what does json.parse do 
Javascript :: nodejs: router by use express and path package 
Javascript :: react tweet embed 
Javascript :: UnhandledPromiseRejectionWarning 
Javascript :: nvm use a particular version 
Javascript :: take a screenshot javascript of canvas 
Javascript :: airbnb react native eslint 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =