Web Analytics Made Easy -
StatCounter Custom Objects and Array Help - CodingForum

Announcement

Collapse
No announcement yet.

Custom Objects and Array Help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Custom Objects and Array Help

    Hi

    I am trying to demonstrate the use of custom objects and arrays for some learners. Does anyone have inline JS coding which provides a simple / straight forward demonstration of the use of an array within a custom object?

  • #2
    Do you mean array/object like posted here?
    http://www.codingforum.net/javascrip...y-objects.html

    Comment


    • #3
      Not quite I have this code which demonstrates a custom object:

      <!DOCTYPE html>
      <html>
      <body>

      <p>Creating and using an object method</p>

      <p id="demo"></p>

      <script>
      function car(make,model,colour) {
      this.make = make;
      this.model = model;
      this.colour = colour;
      this.changeCarMake = function (newCarMake) {
      this.make = newCarMake;
      }
      }
      var car1 = new car("Ford","Focus","Black");
      car1.changeCarMake("BMW");
      document.getElementById("demo").innerHTML =
      "My new car is a " + car1.make;
      </script>

      </body>
      </html>

      What I would like to do is add an array within it which would manipulate or do something with the custom object. Unfortunately, my knowledge of arrays and JS is lacking and need the code expanding to demonstrate this feature? Could you help?

      Comment


      • #4
        Arrays are completely different from objects - you need to be a lot more specific if you want something added that uses an array.
        Stephen
        Learn Modern JavaScript - http://javascriptexample.net/
        Helping others to solve their computer problem at http://www.felgall.com/

        Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

        Comment

        Working...
        X