1

If I use Array.from() method in a blank text qualtrics question, I do not get the expected output. Note that I believe Qualtrics implements javascript with JFE.

For example, the below code is some html that squares [1,2,3] with map and with Array.from().

  • Map works, Array.from doesn't.

  • (Note)I see the same behavior if I input the javascript separately in the qualtrics javascript editor (as opposed to inputting it together with the html as below)

    <p>The initial array before we square it is: <span id="initArr"></span> </p><br>
    
    <p>Squaring the numbers with map gives <span id="mapArr"></span></p><br>
    
    <p>Squaring the numbers with Array.from gives <span id="fromArr"></span></p>
    
         <script>
    
     let initArr = document.getElementById("initArr");
     let mapArr = document.getElementById("mapArr");
     let fromArr = document.getElementById("fromArr");
    
     let basicArr=[1,2,3];
     initArr.innerHTML = basicArr;
         mapArr.innerHTML = basicArr.map(x=>x*x);
         fromArr.innerHTML=Array.from(basicArr,x=>x*x);
         </script>
    

Produces the following output: qualtrics/JFE output example

majmun
  • 131
  • 9
  • Interesting observation but it doesn't really make sense to use `Array.from()` on `basicArr` when it's already an array. Why are you doing so? – Phil May 11 '21 at 23:38
  • 2
    If I had to guess, I'd say that `Array.from` has been implemented without the second `mapFn` argument – Phil May 11 '21 at 23:43
  • @Phil I'm guessing you're right, but I couldn't find anything about this in their documentation, which makes me worried about issues with other commands going unnoticed. As for why I'm using `Array.from()`. Short answer: I'm new to Javascript. Longer answer: In other cases `basicArr` may be sparse for me, in which case I *think* `map` isn't correct to use. – majmun May 12 '21 at 14:19

0 Answers0