1 slice is use for slice a string
2 split is the same as python, with limit
3 include is the same with startswith in python
4 map and filter is used for functions inside
5 concat is used for concat arrays
// slice(startindex, endindex), not include endindex
var A = 'Geeks for Geeks';
b = A.slice(0,5);
c = A.slice(6,9);
d = A.slice(10);
console.log(b);
console.log(c);
console.log(d);
// split is the same as python, but has limit as start index
function func() {
//Original string
var str = 'Geeks for Geeks'
var array = str.split("for");
console.log(array);
var array = str.split("for", 1);
console.log(array);
var check = str.includes("Geeks");
console.log(check);
var check = str.includes("Geeks", 1);
console.log(check);
var check = str.includes("Geeks", 12);
console.log(check);
}
func();
const arr = [1, 2, "3", "4", 5, 6, "7", 8, "9"];
// Converting string to number in array
const arrAsNumbers = arr.map(el => Number(el));
console.log( arrAsNumbers );
const arrStr = ["1", "2", "3"];
const arrAsNumber = arrStr.map(el => parseInt(el));
console.log( arrAsNumber);
function even(el) {
return el % 2 === 0;
}
// Filtering even numbers
// const filteredArr = arrAsNumbers.filter(function (el) {
// return even(el);
// });
// or
const filteredArr = arrAsNumbers.filter(even);
console.log(filteredArr); // [ 2, 4, 6, 8 ]
function funcConcat() {
var num1 = [11, 12, 13],
num2 = [14, 15, 16],
num3 = [17, 18, 19];
console.log(num1.concat(num2, num3));
}
funcConcat();
var alpha = ['a', 'b', 'c'];
console.log(alpha.concat(1, [2, 3]));
var num1 = [23];
var num2 = [89, [67]];
console.log(num1.concat(num2));