xxxxxxxxxx
var streetaddress = addy.split(',')[0];
xxxxxxxxxx
const str = "Learning to code";
// 3 ways to get substring in javascript
// 1. substring() method
// 2. slice() method
// 3. substr() method
console.log(str.substring(0, 5));
console.log(str.substring(0, 5));
console.log(str.substr(2, 5));
xxxxxxxxxx
var str = "Hello World";
// min - 0 max - 10
str.substring(0,10); // Hello Worl
// start- 10 to finished
str.substring(10); // d
xxxxxxxxxx
const str = "Learning to code";
// substring between index 2 and index 5
console.log(str.substring(2, 5));
// substring between index 0 and index 4
console.log(str.substring(0, 4));
// using substring() method without endIndex
console.log(str.substring(2));
console.log(str.substring(5));
xxxxxxxxxx
let str = "abcdefghi"
// index-> 012456789
// str.slice(±start, ±end)
console.log(str.slice(2, 5)) // cde
console.log(str.slice(-5, -3)) // ef
// str.subString(+start, +end) // can't take -ve index
console.log(str.substring(2, 5)) // cde
console.log(str.substring(5, 2)) // cde
// str.substr(±start, length)
console.log(str.substr(2, 5)) // cdefg
xxxxxxxxxx
const string = "mainstring";
const substring = "string";
console.log(string.includes(substring)); //true