js str.indexOf code example
Example 1: encodeuricomponent js
var set1 = ";,/?:@&=+$";
var set2 = "-_.!~*'()";
var set3 = "#";
var set4 = "ABC abc 123";
console.log(encodeURI(set1));
console.log(encodeURI(set2));
console.log(encodeURI(set3));
console.log(encodeURI(set4));
console.log(encodeURIComponent(set1));
console.log(encodeURIComponent(set2));
console.log(encodeURIComponent(set3));
console.log(encodeURIComponent(set4));
Example 2: js indexof string
const paragraph = 'The quick brown fox';
console.log(paragraph.indexOf('T'));
>> 0
console.log(paragraph.indexOf('h'));
>> 1
console.log(paragraph.indexOf('Th'));
>> 0
console.log(paragraph.indexOf('he'));
>> 1
console.log(paragraph.indexOf('x'));
>> 18
Example 3: js yield*
function* g1() {
yield 2;
yield 3;
yield 4;
}
function* g2() {
yield 1;
yield* g1();
yield 5;
}
const iterator = g2();
console.log(iterator.next());
console.log(iterator.next());
console.log(iterator.next());
console.log(iterator.next());
console.log(iterator.next());
console.log(iterator.next());
Example 4: make indexOF in js
function indexOf(arr, value) {
for (let [i, e] of arr.entries()) {
if (value == e) return i;
}
return -1;
}
indexOf([1,2,3], 2);