I have a problem with the slice() method.

Hello,

The code snippet you gave us in your question looks good.

I have tried it and the slice() is fine. You must have some problem with code that you are not showing in your question statement, or an incorrect interpretation of what it should return.

I’ve modified your code a bit to be able to run it, creating an array with sorted values ​​that I can then use to exercise the code.

var listSalaryOrdered = ; //Median of the top 10% poorest: const spliceCountPoor = parseInt((listSalaryOrdered.length * 10) /100); alert(spliceCountPoor); const salariesColpercentage10Poor= listSalaryOrdered.slice(0, spliceCountPoor); alert(salariesColpercentage10Poor.length);

With the execution of this code you get “2” elements in the result array salariesColpercentage10Poor from what I understand that your problem is in another place that you have not shown us. Javascript’s slice() method is working as expected.

See also  Differences between strings in PHP with single and double quotes
Loading Facebook Comments ...
Loading Disqus Comments ...