Pushing Items onto Array
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Pushing Items onto Array
How do you push items onto an array? The following throws an exception.
function ReadAllCribs() { var AllCribs = {}; Project.Variables.Cribs.Reset(); for (; !Project.Variables.Cribs.IsEOF() ;) { AllCribs.push(Project.Variables.Cribs.Value("CribNumber")); //<<< Exception Project.Variables.Cribs.Next(); }
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Whats the error message and is it caused by the semicolon directly after the for statement? that doesnt look right to me.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Also, I think you should be using 'while' rather than 'for' as you are running that loop while a condition is not true, ie. not the end of file.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your all cribs array object should be created with square brackets, using braces creates an object not an array object. I'm going to take a guess here and assume you were trying to append the value with a string "CribNumber" before adding it to array.
function readAllCribs() { var allCribs = []; Project.Variables.Cribs.Reset(); while (!Project.Variables.Cribs.IsEOF() { allCribs.push("CribNumber" + Project.Variables.Cribs.Value); Project.Variables.Cribs.Next(); } }
}
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you. Missed a closing bracket.
// returns list of all cribs function ReadAllCribs() { var AllCribs = []; Project.Variables.Cribs.Reset(); while (!Project.Variables.Cribs.IsEOF()){ AllCribs.push(Project.Variables.Cribs.Value("CribNumber")); Project.Variables.Cribs.Next(); } return AllCribs; }
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The error was not cause by the semicolon but the curly bracket on declaration.
@chrisb wrote:Whats the error message and is it caused by the semicolon directly after the for statement? that doesnt look right to me.
