Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: Array question

  1. #1
    Regular Coder
    Join Date
    May 2011
    Posts
    357
    Thanks
    23
    Thanked 1 Time in 1 Post

    Array question

    Is there a way to create new lines on a array. so if a array cald questions and theres two value questions [0] and questions [1] can i make a function that would create a questions [2]. So i am also wondering if i could do things with a array like sql?

    Edit: Wrong SPelling
    Last edited by sherlockturtle; 10-13-2011 at 12:29 AM.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,014
    Thanks
    79
    Thanked 4,436 Times in 4,401 Posts
    Ready?

    Code:
    var myArray = [ "first element", "second element" ];
    ...
    myArray[2] = "third element"
    myArray[132] = "one hundred thirty second element";
    JavaScript arrays are automatically extended as needed.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,014
    Thanks
    79
    Thanked 4,436 Times in 4,401 Posts
    So i am also wondering if i could do things with a array like sql?
    SQL doesn't support arrays, so if you want to do arrays like SQL the answer is easy: Don't use arrays and thus you WILL be like SQL.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    Regular Coder
    Join Date
    May 2011
    Posts
    357
    Thanks
    23
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Old Pedant View Post
    Ready?

    Code:
    var myArray = [ "first element", "second element" ];
    ...
    myArray[2] = "third element"
    myArray[132] = "one hundred thirty second element";
    JavaScript arrays are automatically extended as needed.
    what do you mean... can you make a new line with a function?
    Edit: and also you said SQL does not use arrays. I meant can you delete and add info to arrays like SQL does to its databases?

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,014
    Thanks
    79
    Thanked 4,436 Times in 4,401 Posts
    what do you mean... can you make a new line with a function?
    ???

    Yes...what does that have to do with arrays? But here...
    Code:
    function getNewLine()
    {
        return "\n";
    }
    or did you mean this?
    Code:
    function addElementToArray( arr, elem )
    {
        arr.push( elem );
    }
    Or what in the world did you mean????

    ********

    I meant can you delete and add info to arrays like SQL does to its databases?
    Yes.

    But if you wanted to use JavaScript to emulate a relational database you would have a big big big job ahead of you.

    Maybe you need to learn how to ask questions. That is, instead of asking questions that could have many different meanings, ask what you are really thinking about. Give enough details that somebody can give you an answer that will actually help you.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    Regular Coder
    Join Date
    May 2011
    Posts
    357
    Thanks
    23
    Thanked 1 Time in 1 Post
    the last one you said is what i wanted. I just was wondering if you could add data to them with a function.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •