Click here to Skip to main content
15,867,993 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
If the element in my array is a character I want to display the element with red color and if the array element is an integer I want to display the element with purple color.

What I have tried:

This is the code I have so far. I cannot figure out how to check if the values are integer or character and where to place the if check in my code.
<script src='https://d3js.org/d3.v7.min.js'></script>
<script>
var newvalues = ['d', 2, 3, 'f', 1];
var s = d3.select("body")
 .selectAll("span")
 .data(newvalues)
 .enter()
 .append('s')
 //.style('color','red')
 .text(function (d, i) {
 return d;
 });
</script>
Posted
Updated 17-Jan-22 1:03am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900