array_map.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. function returnValueSquare(x,y,z)
  6. {
  7. WScript.Echo("value:"+ x + " index:" + y + " Object:" + z);
  8. return x*x;
  9. }
  10. function returnIndexSquare(x,y,z)
  11. {
  12. WScript.Echo("value:"+ x + " index:" + y + " Object:" + z);
  13. return y*y;
  14. }
  15. function returnRandom(x,y,z)
  16. {
  17. WScript.Echo("value:"+ x + " index:" + y + " Object:" + z);
  18. return x*y;
  19. }
  20. Array.prototype[6] = 20;
  21. var x = [1,2,3,4,5];
  22. var y = x.map(returnValueSquare,this);
  23. WScript.Echo(y);
  24. x = [10,20,30,40,50];
  25. y = x.map(returnIndexSquare, this);
  26. WScript.Echo(y);
  27. x = [10,20,30,40,50];
  28. y = x.map(returnRandom, this);
  29. WScript.Echo(y);
  30. x = {0: "abc", 1: "def", 2: "xyz"}
  31. x.length = 3;
  32. y = Array.prototype.map.call(x, returnValueSquare,this);
  33. WScript.Echo(y);
  34. y = Array.prototype.map.call(x, returnIndexSquare,this);
  35. WScript.Echo(y);
  36. y = Array.prototype.map.call(x, returnRandom, this);
  37. WScript.Echo(y);
  38. x = [10,20,30,40,50];
  39. x[8] = 10;
  40. y = x.map(returnValueSquare, this);
  41. WScript.Echo(y);