console.log('a+very+nice+string'.split('+'));
Result: ["a", "very", "nice", "string"]
Separate each character, including white-space:
const res = "How are you doing today?".split("");
console.log(res);
Result: ["H", "o", "w", " ", "a", "r", "e", " ", "y", "o", "u", " ", "d", "o", "i", "n", "g", " ", "t", "o", "d", "a", "y", "?"]
Use the limit parameter:
const resLimit = "How are you doing today?".split("", 3);
console.log(resLimit);
Result:["H", "o", "w"]
Use a letter as a separator:const resO = "How are you doing today?".split("o" );
console.log(resO);
Result:["H", "w are y", "u d", "ing t", "day?"]$breadcrumb-divider: none;
sass variable.
We can even assign SVG icon using the following syntax$breadcrumb-divider: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI4IiBoZWlnaHQ9IjgiPjxwYXRoIGQ9Ik0yLjUgMEwxIDEuNSAzLjUgNCAxIDYuNSAyLjUgOGw0LTQtNC00eiIgZmlsbD0iY3VycmVudENvbG9yIi8+PC9zdmc+);
If we want to remove the separator, we assign none
to the variable$breadcrumb-divider: none;
string, array, function, date boolean, numbers, regular expressions, and objects
too.
All JavaScript values, except primitives, are objects.primitive value
is a value that has no properties or methods.primitive data
type is data that has a primitive value.
JavaScript defines 5 types of primitive data
types:
string
number
boolean
null
undefined
new
:
var car = new Object();
car.model = "Honda Fit";
car.year = 2004;
car.color = "Blue";
2)Using an Object Literal
var car = {model :"Honda Fit", year :"2004", color:Blue};
3)
var car = {};
car.model = "Honda Fit";
car.year = 2004;
car.color = "Blue";
4) Using the Object.create method
var animal1 = Object.create(Animal);
animal1.displayType(); // Output:Invertebrates
5)Using a constructor function
Define the constructor function.
function Car(make, model, year) {
this.make = make;
this.model = model;
this.year = year;
}
then create an object called mycar:
var mycar = new Car('Honda', 'Fit', 2004);
var car = new Object();
car.model = "Honda Fit";
car.year = 2004;
car.color = "Blue";
Now remove property:
delete car.year; // or delete car["year"];
The delete operator deletes both the value of the property and the property itself.
Note: If we use delete on an array, it will create a sparse array
var obj1={
num:10,
name: "luka"
}
obj2 = obj1;
If we change:
obj1.num = 11;
then obj2.num also will be 11...
because we changed obj1.num and it's the location of the reference obj2.num also will be changed...we execute a constructor new object is created
and that object shares characteristics of other objects that are created from the same constructor