<aside> 💡 https://www.github.com/100xdevs-cohort-2/assignments

</aside>

Strings →

Getting a string’s length →

<aside> 💡 This is NOT a function, since you’re not calling it. (Note - no parenthesis around the “function”)

</aside>

// Length
function getLength(str) {
  console.log("Original String:", str);
  console.log("Length:", str.length);
}
getLength("Hello World");

// 11

Finding index of the first appearance of a given word →

// indexOf
function findIndexOf(str, target) {
  console.log("Original String:", str);
  console.log("Index:", str.indexOf(target));
}
findIndexOf("Hello World", "World");

// 6

Finding the index of the last appearance of a given word→

// lastIndexOf
function findLastIndexOf(str, target) {
  console.log("Original String:", str);
  console.log("Index:", str.lastIndexOf(target));
}
findLastIndexOf("Hello World World", "World");

// 12

Getting a Slice of a given string →

<aside> 💡 It DOES NOT include the last parameter, it gives you out the value before the last parameter

</aside>

It gives you the string from the <parameter 1> index, to <parameter 2> - 1 index

function getSlice(str, start, end) {
  console.log("Original String:", str);
  console.log("After slice:", str.slice(start, end));
}
getSlice("Hello World", 2, 7);

// llo W

Getting a Substring from a string →