javascript get last character in string
var hello = "Hello World";
var lastCharOfHello=hello.slice(-1);//d
javascript get last character in string
var hello = "Hello World";
var lastCharOfHello=hello.slice(-1);//d
javascript charat
/*
charAt() method
This method takes in a string and an index as input
and returns the character at that position in the specified string
*/
myString = "Hello World!";
console.log(myString.charAt(0)); // outputs "H"
console.log(myString.charAt(5)); // outputs " "
console.log(myString.charAt(8)); // outputs "r"
// If the specified index is bigger or equal to the length of the string,
// the output will be "".
console.log(myString.charAt(23)); // outputs ""
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
js find index of string in string
// Find the index of a string in a given sentence
function findNemo(sentence) {
let indexOfFirst = sentence.split(' ').indexOf('Nemo') + 1;
if(indexOfFirst >= 0){
return `I found Nemo at ${indexOfFirst}!`;
}
return ("I can't find Nemo :(");
}
console.log(findNemo("I am finding Nemo !")); //"I found Nemo at 4!"
console.log(findNemo("Nemo is me")); //"I found Nemo at 1!"
console.log(findNemo("I Nemo am")); //"I found Nemo at 2!"
.index of javascript
let monTableau = ['un', 'deux','trois', 'quatre'] ;
console.log(monTableau.indexOf('trois')) ;
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us