javascript array

Posted on 2014-08-09
Last Modified: 2014-08-24

From above example, I would like to return to array in javascript. How can I do that?
The ideal result will be like


Question by:ITsolutionWizard
    LVL 107

    Expert Comment

    by:Ray Paseur
    That's a very, very old example and you should not be using it.  We use jQuery for this sort of thing now-a-days and we use JSON instead of XML.

    How does this fit into the PHP Zone?

    Author Comment

    Regardless, I want to use my existing codes base. Please continue if you know how.
    LVL 33

    Accepted Solution

    greetings ITsolutionWizard, , In the code for the w3shools web page you gave they have this -

    as what I consider to be the "Return" from an XML ajax request made with this -"GET","cd_catalog.xml",false);

    so I can not understand what you mean, OR what you might need when you say - "return to array in javascript."
    you say the result would be like -

    but as you may know, , any AJAX return is just a "text" output from the server, if you use the -
    then the javascript will use the text as a XML DOM object with properties, So if you use the XML as the w3schools does, then you will have to use the XML tags to assign values, but you do not get an array.

    If you abandon the XML ajax formatting, then you can get a CSV delimited text, and use -
    to get an array.

    Author Comment

    Then just send me example from xml string to array written in JavaScript
    LVL 33

    Expert Comment

    you say you want an array fron XML? ?, below is untested code , that I just wrote, for here, this -
    for (i=0;i<x.length;i++)
      array1.push( x[j].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue );

    should place the artist values from the XML into array1
    var xmlhttp = false;
    @if (@_jscript_version>=5)try{xmlhttp = new ActiveXObject('Msxml2.XMLHTTP.4.0');} catch(e){
    	try{xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");} catch(e){
    	try{xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");} catch(E){xmlhttp=false;}}}
    	@else xmlhttp = false;
    @end @*/
    if(!xmlhttp && typeof XMLHttpRequest !='undefined'){try{xmlhttp = new XMLHttpRequest();} 
    catch(e){xmlhttp = false;}}
    array1 = [];"GET","cd_catalog.xml",false);
    var x=xmlDoc.getElementsByTagName("CD");
    for (i=0;i<x.length;i++)
      array1.push( x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue );

    Open in new window

    hopefully you can see some of what this does, ask questions if you need more info.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
    SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
    In this tutorial viewers will learn how to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
    In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now