Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I just want to give you a hint for a possible solution without html elements.</p> <p>You can create a new functional object for team:</p> <pre><code>var Team = function (id, name) { this.name = name; this.id = id; } </code></pre> <p>Create an array which will contain teams:</p> <pre><code>var TeamList = []; </code></pre> <p>Add you Teams:</p> <pre><code>TeamList.push(new Team(1, "Team 1")); TeamList.push(new Team(2, "Team 2")); TeamList.push(new Team(3, "Team 3")); TeamList.push(new Team(4, "Team 4")); </code></pre> <p>Write a function which loops trough the list of teams and checks with the id if a team already exists:</p> <pre><code>function containsTeam(id) { for (var i = 0; i &lt; TeamList.length; i++) { if (TeamList[i].id == id) { return true; } } return false; } </code></pre> <p>Just check it:</p> <pre><code>containsTeam(1); //returns true containsTeam(5); //returns false </code></pre> <p>Have a look at the <a href="http://jsfiddle.net/sLTMH/8/" rel="nofollow"><strong>jsFiddle DEMO</strong></a> and open the console to see the output.</p> <p><strong>EDIT:</strong> In addition, to remove an element you can write a function which looks pretty much the same as the containsTeam function. Just use <code>array.splice</code> instead of returning true:</p> <pre><code>function removeTeam(id) { for (var i = 0; i &lt; TeamList.length; i++) { if (TeamList[i].id == id) { TeamList.splice(i, 1); } } } </code></pre> <p>And remove a team:</p> <pre><code>removeTeam(3); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload