ArrayConcat.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 ExplicitToString(value)
  6. {
  7. var result;
  8. if (value instanceof Array)
  9. {
  10. result = "[";
  11. for (var idx = 0; idx < value.length; idx++)
  12. {
  13. if (idx > 0)
  14. {
  15. result += ", ";
  16. }
  17. var item = value[idx];
  18. result += ExplicitToString(item);
  19. }
  20. result += "]";
  21. }
  22. else if (value == null)
  23. {
  24. result = "'null'";
  25. }
  26. else if (value == undefined)
  27. {
  28. result = "'undefined'";
  29. }
  30. else
  31. {
  32. result = value /* .toString() */;
  33. }
  34. return result;
  35. }
  36. function Print(name, value)
  37. {
  38. var result = name + " = " + ExplicitToString(value);
  39. WScript.Echo(result);
  40. }
  41. var a = [1, 2, 3];
  42. Print("a", a);
  43. var b = a.concat(4, 5, 6);
  44. Print("b", b);
  45. var c = [1, [2, 3]];
  46. Print("c", c);
  47. var d = a.concat(4, [5, [6, [7]]]);
  48. Print("d", d);
  49. var e = a.concat([4, 5], [6, 7], [8, [9, [10]]]);
  50. Print("e", e);