“Index von” Code-Antworten

JavaScript Indexof

//indexOf getting index of array element, returns -1 if not found
var colors=["red","green","blue"];
var pos=colors.indexOf("blue");//2

//indexOf getting index of sub string, returns -1 if not found
var str = "We got a poop cleanup on isle 4.";
var strPos = str.indexOf("poop");//9
Grepper

JavaScript Index mit Bedingung

a = [
  {prop1:"abc",prop2:"qwe"},
  {prop1:"bnmb",prop2:"yutu"},
  {prop1:"zxvz",prop2:"qwrq"}
];
    
index = a.findIndex(x => x.prop2 ==="yutu");

console.log(index);
Clever Crane

Index von

/*To search for the index of a substring or string within an array, 
use .indexOf() 
If you search for something that isn't there, the function will return -1*/

let mechs = ["madcat", "blood asp", "atlas"];
console.log(mechs.indexOf("madcat"); //returns 0
console.log(mechs.indexOf("atlas"); //returns 2

let clan = "nova cat";
console.log(clan.indexOf("a")); /*returns 3 (Only the first instance of the
character is used.*/
console.log(clan.indexOf("cat")); /*returns 5 (Finds the index of the beginning
character)*/
console.log(clan.indexOf("s")); //returns -1
Faithful Fox

Javasript -Array -Index

var array = [2, 9, 9];
array.indexOf(2);     // 0
array.indexOf(7);     // -1
array.indexOf(9, 2);  // 2
array.indexOf(2, -1); // -1
array.indexOf(2, -3); // 0
Cookie_Wookie_7

uneingeschränkt

const beasts = ['ant', 'bison', 'camel', 'duck', 'bison'];

console.log(beasts.indexOf('bison'));
// expected output: 1
Ugliest Unicorn

Index von

public int indexOf(int value)
    {
        int index = -1;
        for (int i = 0; i < size; i++)
        {
            if (elementData[i] == value)
            {
                index = i;
            }
        }
        return index;
    }
Sid Potti

Ähnliche Antworten wie “Index von”

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen