Javascript String





What is a String?

A string is similar to an Array, but uses different syntax.


Syntax:


string.includes(searchvalue, start)


searchvalue This is required and is the string to search for.

start this is optional and the default is set at 0. This is the position to start your search.

The return value is also a Boolean -- a.k.a. true or false



Example of fromIndex with String:

				
Ex.1:

// var arr = ['red', 'blue', 'yellow'];

--> When the default index sets at 0 

	arr.includes('yellow', 3); // false  

	arr.includes('yellow', 100) // false



Ex.2:

var str = "Hello world, welcome to the universe.";
var n = str.includes("world");

--> the result of 'n' will be: true 



Ex.3:

var arr = ['a','b','c'];
var str = "abc";

console.log(arr.length); // 3
console.log(str.length); // 3

console.log(arr[0]); // a
console.log(str[0]); // a

console.log(arr === str); // false

console.log(typeof str); // string
console.log(typeof arr); // object
		
		

			

Home Page

What are Arrays?