Js to find a loop algorithm?

I want to implement a small navigation function with an array of js.

I turned it into this for him.

$arr = ["1001 | computer", "1002 | personal computer", "99" | Asustek computer," 100" | Asustek Notebook];

what I"m going to do now is my input. For example: 99,

then start looking for this array and output 1001 ~ 1002 ~ 99. Everything after 99 is truncated.

enter 1002 and print out 1001.

how do I get it?

var length = myArray.length;
for (var i = 0; i < length; iPP) {
    if(myArray[i].indexOf(id) == -1){ 
    } //
    
    

somebody give me some advice!

Apr.29,2021

No algorithm is needed

var myArray = ['1001|','1002|','99|','100|'];
var id = 100;
var result = [];
for (var i = 0; i < myArray.length; iPP) {
    var sec = myArray[i].split('|', 2);
    var theid = parseInt(sec[0]);
    var thename = sec[1];
    result.push(thename);
    if (theid == id) {
        break;
    }
}
console.log(result);

ES6:

let myArray = ['1001|','1002|','99|','100|'];
let id = 99;
let last = myArray.findIndex(v=> parseInt( v.split('|', 2)[0] ) ===id )
myArray.slice(0, last+1).forEach(v=> alert( v.split('|', 2)[0] ));

function findArr(target,myArray){
  let index = myArray.findIndex(item=>parseInt(item) == target);
  return index > -1 ? myArray.slice(0,index+1) : [];
}; 
let targetArr = findArr(99, ['1001|','1002|','99|','100|']);
targetArr.forEach(item => console.log(parseInt(item)));
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3a814-345e7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3a814-345e7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?