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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2016
    Posts
    7
    Thanks
    5
    Thanked 0 Times in 0 Posts

    compare content of array and object

    Hi
    I have an object array . The objects are generated programmatically and their key values are added to the DOM using an array. What I would like to know is how to relocate the object from which the values emanate and remove it from its container if the array is removed from the DOM could anybody please help me?


    I have

    Code:
    var continents = []
    It contains three objects with the name of a continent and its population which are the values of two fieldsets name and population.
    Code:
    var continent ={}
    continent [Name] = the value population
    continent [Population]  = the value of name
    example:

    I am not sure how to identify the object and then delete it

  2. #2
    Master Coder sunfighter's Avatar
    Join Date
    Jan 2011
    Location
    Washington
    Posts
    6,251
    Thanks
    30
    Thanked 859 Times in 857 Posts
    Really not sure what your asking. Your array should only have two elements the name of a continent and it's population.
    And why do you want to delete anything?

    And this line
    if the array is removed from the DOM
    threw me cause the array is part of the JS and not the DOM.
    Anyway here is something that might or might not help:
    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title>New document</title>
    <style type="text/css">
    #show{
    	display: none;
    }
    </style>
    </head>
    <body>
    <select onchange="doit(this.value);">
    <option value="">Pick a continent</option>
    <option value="Asia">Asia</option>
    <option value="Africa">Africa</option>
    <option value="Antarctica">Antarctica</option>
    <option value="Australia">Australia</option>
    <option value="Europe">Europe</option>
    <option value="North_America">North America</option>
    <option value="South_America">South America</option>
    </select>
    <div id="show">
    The population of <span id="in"></span> is <span id="info"></span>
    </div>
    
    <script>
    var continents = {
    Asia:			4164252000,
    Africa:			1022234000,	
    Antarctica:		4490,
    Australia:		29127000,
    Europe:			738199000,	
    North_America:	542056000,
    South_America:	392555000};
    function doit(name){
    document.getElementById("in").innerHTML = name;
    document.getElementById("info").innerHTML = continents[name];
    document.getElementById("show").style.display = "block";
    }
    
    </script>
    </body>
    </html>
    Evolution - The non-random survival of random variants.
    Physics is actually atoms trying to understand themselves.

  3. Users who have thanked sunfighter for this post:

    princesse (03-09-2016)


 

Tags for this Thread

Posting Permissions

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