PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, September 6, 2022

[FIXED] Why my javascript looping return error missing 'of ' after for

 September 06, 2022     ajax, for-loop, javascript     No comments   

Issue

dataPoints: [
    for(i = 0;i<json.data.length;i++){
    { label: json.data[i][1], y: parseInt(json.data[i][2])}
    }]

I have code like that but I see an error on the console

SyntaxError: missing 'of' after for

Does anyone know why? I did search on Google, but nothing can tell me why.


Solution

Obviously, You will get incorrect syntax. Seems you want to create an array so use Array.map()

dataPoints: json.data.map(function (d) {
    return {
        label: d[1],
        y: parseInt(d[2])
    }
})


Answered By - Satpal
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing