-4

How can i get object name in JAVASCRIPT

--

let smthng = {1,2,3}

console.log(smthng.toString(),smthng);

-> my expect : smthng {1,2,3}

Bill Hileman
  • 2,798
  • 2
  • 17
  • 24

1 Answers1

-1
let smthng = {a:1,b:2,c:3}
console.log({ smthng: smthng }) // or console.log({ smthng }); should print {smthng:{a:1,b:2,c:3}}
Ethan Doh
  • 508
  • 1
  • 7
  • 9
  • sorry My desc was short i was trying to catch variable name on console so let smthng = [1,2,3] i need my console to be printed as //// smthng : [1,2,3] //// one another example let another = [1,2,3] i need my console to be printed as //// another : [1,2,3] //// one another example – jamiesomethinggood Feb 05 '20 at 02:57
  • console.log({ smthng }) or console.log({ another }) will do what you want. Both will print {smthng:[1,2,3]} and {another:[1,2,3]} – Ethan Doh Feb 05 '20 at 03:04
  • While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value. – RyanNerd Feb 05 '20 at 06:45