how do I check an array of tuples for a value in index[0] and if there is a match, display the value at index [1] of the matching tuple

Phantom Jake

I have an array of tuples:

var tuparray: [string, number][];
 tuparray = [["0x123", 11], ["0x456", 7], ["0x789", 6]];

const addressmatch = tuparray.includes(manualAddress);

I want my function to check if the tuparray contains a user input (string), manualAddress. If it finds a match in any of the tuples, it should display the value from the number at [1] of the tuple.

if (addressmatch){
console.log("address qualifies for [matched tuple number here]");

Any help on this would be greatly appreciated!

Newbie

Just use find() on the Array and provide a lambda function to evaluate the match.

var tuparray = [["0x123", 11], ["0x456", 7], ["0x789", 6]];

function includes(manualAddress) {
    const found = tuparray.find(x => x[0] == manualAddress)
    
    if (found) {
        console.log(`address qualifies for ${found[1]}`)
    } else {
        console.log(`Not found`)
    }
}

includes('0x123')
includes('0x456')
includes('0x111')

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I check in JavaScript if a value exists at a certain array index?

How can I remove duplicate tuples from a list based on index value of tuple while maintaining the order of tuple?

PHP - How do I unset an array index by value inside that index

how do i check if my value match with other like a pair matching game

How do I match an Index in 1 list with a different list index value and output the 2nd list values?

Elixir: How do I check if an element exists in a specific index of a tuple in an array?

How to display the value of an array by the index number?

PHP - How to check if array contains a value by index?

How to check if an array index contains a value

how do I find the index of an specific value in numpy array?

How do I find the index of the maximum value of an array?

How do I get an Array item's opposite index and value?

How do I call elements of an array as their index numerical value

How do I find the array index with its highest value with vhdl?

How do i get the value of first index in a returned List of array

How do I find the maximum value of a row index in a numpy array?

#Value! Error with array index and match

AngularJS display data of index that has matching value

How can I compare a string A1 with a value A2 (index 0's) in and array values?

index value of the tuples

display array index value JavaScript

How do I join six list of tuples into a pandas dataframe using the first value of each tuple as the key?

How do I save python dictionary into a dataframe if the value of dictionary is tuple of tuples

Check my tuple of tuples and change the given value

Get a tuple value in a tuple by index

How to check if an ArrayList of 1D Arrays (EX : int [ ] order = new int [2] ) has a value in index 0 of the 1D array, if so update index 1

How do I check user parameters to match a value in firebase?

Check for skipped index in array if the value was incremented by more than 1

Repeat 2D array index tuples according to value in index