Set array value from a function - Javascript Object

Javascript examples for Object:prototype

Description

Set array value from a function

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=( function() {// ww  w.  j a  v  a2s  .  co  m
function Foo(arr) {
    this.arr = arr;
}
var f = new Foo(['a', 'b', 'c', 'd']);
Foo.prototype.setValue = function(index, v) {
    this.arr[index] = v;
}
idx = 0;
f.setValue(idx, "Z");
console.log(f);
    });

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials