'How can we Create JavaScript Objects which has functions [duplicate]
var cars = {
"c1":"BMW",
"c2":"Volvo",
"c3":["Saab","jas"],
"c4":{"Ford":"cdsnj", "Ford1":"cdsnj", "Ford2":"cdsnj"}
"myMethod" = () =>{
console.log("eFNJVSL")
},
};
Solution 1:[1]
Replace the = with :
var cars = {
"c1":"BMW",
"c2":"Volvo",
"c3":["Saab","jas"],
"c4":{"Ford":"cdsnj", "Ford1":"cdsnj", "Ford2":"cdsnj"},
"myMethod" : () =>{
console.log("eFNJVSL")
},
};
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ran Turner |
