0

I successfully created 3 VSCode snippets, I added the 4th one.

{
      "for": {
        "prefix": "for",
        "body": "for (i = 0; i < ${1:}.length; i++) {
            console.log(${1:}[i]);
        }"
      }

  }

IDE is highlighted as red, and I am not able to see it in the snippet list.

enter image description here

How can I fix that ?

Goal is to

As I type/select for should add this code. Hint: for is my snippet prefix.

for (i = 0; i < responses.length; i++) {
    console.log(responses[i]);
}
3
  • in json, "\n" means newline Commented Apr 30, 2022 at 11:57
  • or I can specify it as an array[ ] of body property. Commented Apr 30, 2022 at 12:03
  • Javascript " strings are not multi-line, do the default forXXXsnippets not work Commented Apr 30, 2022 at 13:00

2 Answers 2

2

I just went through the user defined snippets documentation and looks like you have to put the body content in an array. Can you please try this way :

{
  "for": {
    "prefix": "for",
    "body": ["for (const ${2:element} of ${1:array}) {", "\t$0", "}"]
  }
}
Sign up to request clarification or add additional context in comments.

Comments

0

I found a working solution, I achived it by doing this:

"FOR": {
    "prefix": "for",
    "body": [
        "for (var i = 0; i < ${array}.length; i++) {",
        "\tconsole.log(${array}[i]);",
        "\t$0",
        "}"
    ]
}

Result

As I type

enter image description here

As I select

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.