“Indice de” Réponses codées

Index JavaScript

//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

Index javascript avec condition

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

Indice de

/*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

Index de tableau Javasript

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

indéfafof

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

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

Indice de

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

Réponses similaires à “Indice de”

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code