Click here to Skip to main content
15,169,823 members
Home / Discussions / JavaScript
   

JavaScript

 
QuestionArea of ​​a 2d room Pin
Member 1550401122hrs 57mins ago
MemberMember 1550401122hrs 57mins ago 
SuggestionRe: Area of ​​a 2d room Pin
Richard MacCutchan22hrs 49mins ago
mveRichard MacCutchan22hrs 49mins ago 
GeneralRe: Area of ​​a 2d room Pin
Member 1550401122hrs 37mins ago
MemberMember 1550401122hrs 37mins ago 
QuestionHow to solve this in js Pin
Miraz Uddin17-Jan-22 19:57
MemberMiraz Uddin17-Jan-22 19:57 
AnswerRe: How to solve this in js Pin
Richard Deeming17-Jan-22 22:34
mveRichard Deeming17-Jan-22 22:34 
QuestionHow to solve this in js Pin
Miraz Uddin17-Jan-22 19:53
MemberMiraz Uddin17-Jan-22 19:53 
AnswerRe: How to solve this in js Pin
Richard Deeming17-Jan-22 22:34
mveRichard Deeming17-Jan-22 22:34 
GeneralString Pin
SHAFI CANVASS6-Jan-22 13:40
MemberSHAFI CANVASS6-Jan-22 13:40 
GeneralRe: String Pin
RedDk6-Jan-22 14:07
MemberRedDk6-Jan-22 14:07 
GeneralRe: String Pin
jhonaa11-Jan-22 22:24
Memberjhonaa11-Jan-22 22:24 
QuestionReplecing .data() jQuery with JavaScript Pin
Member 154605438-Dec-21 10:46
MemberMember 154605438-Dec-21 10:46 
AnswerRe: Replecing .data() jQuery with JavaScript Pin
Richard Deeming8-Dec-21 23:12
mveRichard Deeming8-Dec-21 23:12 
QuestionCan't figure out why I'm not able to access my projects array within my JSON object Pin
jkirkerx23-Nov-21 14:20
professionaljkirkerx23-Nov-21 14:20 
I have this very long process that creates a JSON array of projects. It takes 10 minutes to generate the JSON.
I'm trying to extract my projects array from within this JSON, and have converted the JSON string to an JavaScript object.
Suppose to be able to call jsonObject.projects and loop it, but it keeps coming up with an error "projects is undefined". When I parse again projects, I get "JSON.parse unexpected character at line 1"

I've done this so many times, but this time has me baffled.

This is my code:
function loadProjectsUpdated(partId) {

    const projectsContainer = document.getElementById('projectsContainer');
    const jsonProjectElement = document.getElementById('updateProjectCost_jsonProjectResponse');
    const jsonObject = JSON.parse(jsonProjectElement.value);

    console.log('jsonObject', jsonObject);
    const projects = jsonObject.projects;
    console.log('projects', projects);

    for (const project of projects) {

        console.log('projectNumber', project.projectNumber)

        if (project.partId === partId) {

            console.log('we have a match');

        }

    }

}

And my console results:
I can see I have a object here.

jsonObject
Array [ {…} ]​
0: Object { partId: "REF_EL_003", vendorId: "7", projects: (411) […] }​​
partId: "REF_EL_003"​​
projects: Array(411) [ {…}, {…}, {…}, … ]​​​
[0…99]​​​​
0: Object { projectNumber: "4725", projectStage: "construction", projectVersion: 7, … }​​​​​
partId: "REF_EL_003"​​​​​
projectCostDifference: 0​​​​​
projectCreated: "2019-02-05"​​​​​
projectCustomerName: "XXX - DXXX"​​​​​
projectNewActualCost: 89912.66​​​​​
projectNumber: "4725"​​​​​
projectOriginalActualCost: 89912.66​​​​​
projectStage: "construction"​​​​​
projectVersion: 7​​​​​
taskId: "XX_XX_022"​​​​​
If it ain't broke don't fix it
Discover my world at jkirkerx.com

AnswerRe: Can't figure out why I'm not able to access my projects array within my JSON object Pin
Richard Deeming23-Nov-21 22:31
mveRichard Deeming23-Nov-21 22:31 
GeneralRe: Can't figure out why I'm not able to access my projects array within my JSON object Pin
jkirkerx24-Nov-21 10:24
professionaljkirkerx24-Nov-21 10:24 
GeneralRe: Can't figure out why I'm not able to access my projects array within my JSON object Pin
Richard Deeming24-Nov-21 22:33
mveRichard Deeming24-Nov-21 22:33 
GeneralRe: Can't figure out why I'm not able to access my projects array within my JSON object Pin
jkirkerx25-Nov-21 8:37
professionaljkirkerx25-Nov-21 8:37 
Questionwait for fetch to finish within a for each loop Pin
jkirkerx16-Nov-21 14:35
professionaljkirkerx16-Nov-21 14:35 
AnswerRe: wait for fetch to finish within a for each loop Pin
Richard Deeming16-Nov-21 23:49
mveRichard Deeming16-Nov-21 23:49 
GeneralRe: wait for fetch to finish within a for each loop Pin
jkirkerx17-Nov-21 6:52
professionaljkirkerx17-Nov-21 6:52 
QuestionRecommended Apps to learn java for student? Pin
kennymanda11-Nov-21 20:44
professionalkennymanda11-Nov-21 20:44 
AnswerRe: Recommended Apps to learn java for student? Pin
OriginalGriff11-Nov-21 20:45
mveOriginalGriff11-Nov-21 20:45 
GeneralMessage Closed Pin
16-Dec-21 12:25
Membercryptorobotics16-Dec-21 12:25 
AnswerRe: Recommended Apps to learn java for student? Pin
Richard MacCutchan11-Nov-21 22:04
mveRichard MacCutchan11-Nov-21 22:04 
QuestionUploading image using JQuery AJAX Pin
Alex Dunlop10-Nov-21 19:56
MemberAlex Dunlop10-Nov-21 19:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.