Results: 1580
Notes
  • Newest first
  • Oldest first
  • Newest first(All)
  • Oldest first(All)
const target = { a: 1, b: 2 };
const source = { b: 4, c: 5 };

const returnedTarget = Object.assign(target, source);
// using object.assign method first object will be simply concatenated to second one
also we can write empty {} brackets and set it empty object as a first argument
by Luka Tatarishvili
4 years ago
0
JavaScript
Objects tutorial 6
0
json.parse to clone object
let method4 = JSON.parse(JSON.stringify(car))
// JSON.stringify(car)
// JSON.parse('{"mark":"Ford","model":"Raptor"}')

JSON.PARSE method just converts it into a string then parses so it can clone nested objects too
by Luka Tatarishvili
4 years ago
0
JavaScript
Objects tutorial 6
0
rest operator clone
// rest operator

let {...method2} = car
// let {model, ...rst} = car
// let {model, ...car} = {year:"2017", ...car}
rest operator is allows us to skip some propoerties.. we can also use it with spread operator and it will more useful because it can add or update properties at the same time
by Luka Tatarishvili
4 years ago
0
JavaScript
Objects tutorial 6
0
spread operator clone
// spread operator

let method1 = {...car}
// method1 === car  // false
// method1.model = "F150"
// let sprd = {...car, color: "black", model:"ranger"}
if the comparison returns false so it cloned successfully because they will refer to a different location on memory. So we can add or update properties with another parameters after spread operator..
by Luka Tatarishvili
4 years ago
0
JavaScript
Objects tutorial 6
0
// merge array
 var parents = ["mom", "dad"]
  var children = ["mike", "jenny"]
  var family = parents.concat(children);
Result of family variable:
["mom", "dad", "mike", "jenny"]
by Luka Tatarishvili
4 years ago
0
JavaScript
array
0
// join array elements into string.

var family = ["mom", "dad", "mike", "jenny"]
var fstr = family.join();

output:
fstr =  "mom,dad,mike,jenny"
by Luka Tatarishvili
4 years ago
0
JavaScript
array
0
function hello() { alert('Hi there!'); }

setTimeout(hello, 5000)
or
setTimeout( function() { alert('Hi there!'); }, 5000 )
by Luka Tatarishvili
4 years ago
0
JavaScript
array
0
Configurable Attribute
: Specifies whether the property can be deleted or changed.
Enumerable
: Specifies whether the property can be returned in a for/in loop.
Writable:
Specifies whether the property can be changed.
by Luka Tatarishvili
4 years ago
0
JavaScript
objects
0
create object property:
var christmasList = {mike:"Book", jason:"sweater" }
then delete some property with delete keyword
delete christmasList.mike;  // deletes the mike property
by Luka Tatarishvili
4 years ago
0
JavaScript
objects
0
To find out if a property exists on an object we can use in operator:
var school = {schoolName:"MIT"};
console.log("schoolName" in school);  // true because schoolName is an own property on the school object

console.log("schoolType" in school);  // false because  because we did not define a schoolType property on the school object

// Prints true because the school object inherited the toString method from Object.prototype. 
console.log("toString" in school);  // true
by Luka Tatarishvili
4 years ago
0
JavaScript
objects
0
Results: 1580