-5
var cars = {
    "c1":"BMW", 
    "c2":"Volvo", 
    "c3":["Saab","jas"], 
    "c4":{"Ford":"cdsnj", "Ford1":"cdsnj", "Ford2":"cdsnj"}
    "myMethod" = () =>{
        console.log("eFNJVSL")
    },
};

The way I tried

Teemu
  • 22,918
  • 7
  • 53
  • 106
  • `=` should be `:` – Andreas Feb 12 '22 at 12:19
  • [Working with objects - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects) – Andreas Feb 12 '22 at 12:20
  • You're also missing a `,` after the `c4` definition. – rickdenhaan Feb 12 '22 at 12:20
  • If you want an arrow function, then as the others have said, you just use `:` rather than `=`; it's still a property initializer, doesn't matter what the *value* of the property is, it still comes after `:`, not `=`. If it doesn't need to be an arrow function, you could use [method syntax](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Method_definitions): `myMethod() { /*...*/ }`. (There's also no need for your property names to be in double quotes. It's fine if they are, but all of the ones you've shown are valid identifiers, so you don't need the quotes.) – T.J. Crowder Feb 12 '22 at 12:31

1 Answers1

-1

Replace the = with :

var cars = {
    "c1":"BMW", 
    "c2":"Volvo", 
    "c3":["Saab","jas"], 
    "c4":{"Ford":"cdsnj", "Ford1":"cdsnj", "Ford2":"cdsnj"},
    "myMethod" : () =>{
        console.log("eFNJVSL")
    },
};
Ran Turner
  • 14,906
  • 5
  • 47
  • 53