How can i use handlebars data in front end js variable

I'm passing an object array to handlebars. i'm retrieving it on front end like this

{{this.coment}}

The object contains this:

`{
    _id: "5c527707e28b4fac758cc674",
    sectionId: "2",
    comments: [
      {
        replies: [],
        authorAvatarUrl:
          "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRDW3D0Emu0_gpP-tAEGPjW88zSabvpdICv6BaoNLArqY3xB4NA",
        authorName: "Jesus Zuñiga Vega",
        authorId: "1",
        authorUrl: "",
        comment: "Test",
        id: "72845"
      }
    ]
  },
  {
    _id: "5c5279f2e28b4fac758cc761",
    sectionId: "3",
    comments: [
      {
        replies: [],
        authorAvatarUrl:
          "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRDW3D0Emu0_gpP-tAEGPjW88zSabvpdICv6BaoNLArqY3xB4NA",
        authorName: "Jesus Zuñiga Vega",
        authorId: "1",
        authorUrl: "",
        comment: "Test2",
        id: "37940"
      }
    ]
  },
  {
    _id: "5c527ce2e28b4fac758cc887",
    sectionId: "1",
    comments: [
      {
        replies: [],
        authorAvatarUrl:
          "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRDW3D0Emu0_gpP-tAEGPjW88zSabvpdICv6BaoNLArqY3xB4NA",
        authorName: "Jesus Zuñiga Vega",
        authorId: "1",
        authorUrl: "",
        comment: "Hello",
        id: "77251"
      }
    ]
  }`

Note that it is missing the "[ ]" of the array

i want to know if it is possible to put the data in a js variable to use it in front end like this:

var existingComments = [
  {
    _id: "5c527707e28b4fac758cc674",
    sectionId: "2",
    comments: [
      {
        replies: [],
        authorAvatarUrl:
          "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRDW3D0Emu0_gpP-tAEGPjW88zSabvpdICv6BaoNLArqY3xB4NA",
        authorName: "Jesus Zuñiga Vega",
        authorId: "1",
        authorUrl: "",
        comment: "Test",
        id: "72845"
      }
    ]
  },
  {
    _id: "5c5279f2e28b4fac758cc761",
    sectionId: "3",
    comments: [
      {
        replies: [],
        authorAvatarUrl:
          "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRDW3D0Emu0_gpP-tAEGPjW88zSabvpdICv6BaoNLArqY3xB4NA",
        authorName: "Jesus Zuñiga Vega",
        authorId: "1",
        authorUrl: "",
        comment: "Test2",
        id: "37940"
      }
    ]
  },
  {
    _id: "5c527ce2e28b4fac758cc887",
    sectionId: "1",
    comments: [
      {
        replies: [],
        authorAvatarUrl:
          "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRDW3D0Emu0_gpP-tAEGPjW88zSabvpdICv6BaoNLArqY3xB4NA",
        authorName: "Jesus Zuñiga Vega",
        authorId: "1",
        authorUrl: "",
        comment: "Hello",
        id: "77251"
      }
    ]
  }
];

Any help will be much aprecciated thank you very much!!!

#javascript #node-js #express

2 Likes1.70 GEEK