There is an issue with the syntax in your for-loop control where a closing parenthesis is missing

When I try to navigate through the arrays from 1 to 4 in the given JSON data, Firebug shows me an error message:

SyntaxError: missing ) after for-loop control
[Break On This Error]   

for( x in LGIntake.corpCodeOptions.marketSegment.1){

StartI...aseId=0 (line 675, col 50)

LGIntake = {};
LGIntake.corpCodeOptions = {};
LGIntake.corpCodeOptions.marketSegment = {
"1":[["FEP","FEP"],["HA","HA"],["HWB","HWB"],["JG","JG"],["LG","LG"],
     ["MAC","MAC"],["NAC","NAC"],["NAL","NAL"],["NAP","NAP"],["NAU","NAU"]],
"2":[["ERS","ERS"],["FEP","FEP"],["HRP","HRP"],["LGC","LGC"],["LGL","LGL"],
     ["MGC","MGC"],["MGL","MGL"],["NAC","NAC"],["NAP","NAP"],["NPB","NPB"],
     ["NPH","NPH"],["NPI","NPI"],["NPP","NPP"],["NPR","NPR"],["NPS","NPS"],
     ["NRSG","NRSG"],["SRK","SRK"],["TAC","TAC"],["TCF","TCF"],["TCI","TCI"],
     ["THE","THE"],["TRS","TRS"]],
"3":[["AFG","AFG"],["ALI","ALI"],["APS","APS"],["FEP","FEP"],["HSC1","HSC1"],
     ["HSC2","HSC2"],["LAN","LAN"],["LGN","LGN"],["NAP","NAP"],["PAK","PAK"],
     ["PSA","PSA"],["RA","RA"],["RC","RC"]],
"4":[["COMA","COMA"],["FEP","FEP"],["LG","LG"],["NAC","NAC"],["NAP","NAP"],
     ["NRMM","NRMM"],["NRSG","NRSG"],["ORAA","ORAA"]]
}; 

Here is my JavaScript code:

function initMarketSegment(corpCode){
    var corpCodeList = new Array();
    if(corpCode == "1"){
        for( x in LGIntake.corpCodeOptions.marketSegment.1){
            marketSegment.option[marketSegment.option.length] = new Option('LGIntake.corpCodeOptions.marketSegment.1[x]','LGIntake.corpCodeOptions.marketSegment.1[x]');
        }
    }
    else if(corpCode == "2"){
        for( x in LGIntake.corpCodeOptions.marketSegment.2){
            marketSegment.option[marketSegment.option.length] = new Option('LGIntake.corpCodeOptions.marketSegment.2[x]','LGIntake.corpCodeOptions.marketSegment.2[x]');
        }
    }
    else if(corpCode == "3"){
        for( x in LGIntake.corpCodeOptions.marketSegment.3){
            marketSegment.option[marketSegment.option.length] = new Option('LGIntake.corpCodeOptions.marketSegment.3[x]','LGIntake.corpCodeOptions.marketSegment.3[x]');
        }
    }
    else if(corpCode == "4"){
        for( x in LGIntake.corpCodeOptions.marketSegment.4){
            marketSegment.option[marketSegment.option.length] = new Option('LGIntake.corpCodeOptions.marketSegment.4[x]','LGIntake.corpCodeOptions.marketSegment.4[x]');
        }   
    }
}

Answer №1

As stated in the EMCAScript 5.1 specification, JavaScript identifiers must not begin with a number. This means that using "1" as a property is not considered a valid identifier within your JSON code. Nevertheless, you can still reference it by utilizing

LGIntake.corpCodeOptions.marketSegment[1]
.

For more information, please visit .

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The TypeScript optional callback parameter is not compatible with the anonymous function being passed to it

Encountering an issue with TS callbacks and function signatures. Here is my scenario: ... //inside a class //function should accept a callback function as parameter refreshConnection(callback?: Function) { //do something //then ca ...

Vue.js: SCSS @import being overlooked

I've found great success using VueJS in two different projects. As I prepare to launch these projects, I'm encountering an issue when generating the files with npm run build. One project, created recently, is working fine. However, the other pro ...

Unraveling a String with an Array of Dictionaries in Swift through Decodable Protocol

The JSON response is:- { "id" = "1" "message" = "SUCCESS" "data" = "[{\"name\":"FirstName",\"office_id\":1111,\"days_name\": ...

Obtain the date value in the format of month/day/year

How can I retrieve the date from 2 months ago and format it as MM/DD/YYYY? I tried this code snippet, but it's returning a value in the format "Tue Feb 11 14:30:42 EST 2014". var currentDate = new Date(); currentDate.setMonth(currentDate.getMonth() ...

The application of knockoutjs bindings is restricted to specific ids and cannot be used on any

In my project, I have multiple views where each one applies bindings to its own tag individually. Here is a snippet of the code: (Please note that some code has been omitted for brevity. For a more complete example, you can view the full fiddle here: http ...

What could be the reason for the NODE_DEBUG=fs environment variable not working as expected?

According to the Node.js documentation on the fs module at https://nodejs.org/api/fs.html#fs_file_system: To obtain a trace back to the original call site, you can set the NODE_DEBUG environment variable: Here is an example of setting the fs environmen ...

What is the best way to validate if fields are blank before sending a message using the button?

<template> <div> <div class="form-group"> <label for="name">First Name</label> <input type="text" class="form-control" v-model="firstName" placeholder="Ente ...

"Upon calling an asynchronous method within another method, it appears that no progress is being displayed

I've created a `node-js` `db.js` class that retrieves an array of data for me. //db.js const mysql = require('mysql'); var subscribed = []; const connection = mysql.createConnection({ host: 'localhost', user: 'root' ...

Convert Python strings into HTML JavaScript blocks using Jinja2

Having trouble passing a string to an HTML page in the "<script>" block. I am currently using Python, Flask, and Jinja2. Python code: def foo(): return myString #"[{title: 'Treino 7-Corrida',start: '2015-12-08',color: '#d ...

Changing a numeric string into a number within an Angular 2 application

Looking for advice on comparing Angular 2 expressions. I have an array of data stored as numeric strings in my database and I need to convert them to numbers before applying a condition with ngClass for styling purposes. Any suggestions on how to perform ...

Difficulty in toggling on and off several form elements with JavaScript

Trying to control multiple form elements on an HTML page with JavaScript has presented a challenge for me. In my form, each row contains a checkbox that should enable/disable the elements on that row. The issue I'm facing is that only the first two f ...

Is there a way to interact with a DOM element through clicking and then pass it as a variable using PHP?

Is there a way to configure a table so that data from a specific row is sent to a PHP script and displayed in a section on the website when the user clicks on that row? I am looking to pre-fill a data entry form with information from a selected row, allow ...

Minimizing repeated autofocus calls in material-ui's <TextField> component

In the realm of coding with material-ui, when dealing with the <TextField> component, it's important to keep in mind that the solution may actually lie within React itself. Let's paint a scenario where we're crafting a basic login for ...

Issue with click function not activating in Chrome when using Angular 6

I am facing an issue where the (click) function is not triggering in my select tag when I use Google Chrome, but it works fine in Mozilla. Below is my code: <div class="col-xl-4 col-lg-9"> <select formControlName="deptId" class="form-control ...

Charting with multiple series

I am exploring a unique approach to creating a timeline chart. I am seeking advice on the best way to implement this in the world of JavaScript. My challenge is to create interactive milestones with descriptive text displayed on the Y axis, while displayi ...

Flashing white screen when transitioning between pages on phonegap iOS system

I'm currently using phonegap for my iOS application project. Interestingly, I've noticed a slight white flicker/flash when navigating between pages in the app. To address this issue, I have refrained from using jquery mobile and instead relied ...

Failure to receive a response from ExpressJS jQuery ajax Post request

I am facing an issue with my Ajax post request as I am unable to retrieve any values in the console. Can anyone point out what might be missing here? Node.js app.post('/register',function(req,res) { //console.log(JSON.stringify(req.body)); ...

Malfunction in function calling due to improper ajax response (JSON)

There seems to be an issue with the success function not being executed in the JavaScript code below: $.ajax({ type: 'POST', url: 'http://localhost/hf_latest_desktop/st_pages/user_area/acc_buttons/pass_change/pass_ ...

The encoding error in the encoding process must adhere to valid encoding standards

I recently developed a basic program that utilizes process.stdin and process.stdout. However, when I executed the program and tried to input a value for stdout, an error message popped up stating "TypeError: 'encoding' must be a valid string enco ...

Implement a contact form using backend functionality in a ReactJS application

Currently, I am in the process of developing my first website using reactjs. My focus right now is on completing the contact form page, and I have already spent 2 days on it. To handle email functionality, I am utilizing nodemailer with a Gmail account tha ...