Relative Content

Tag Archive for javascriptjson

json_encode() output space fetching from PHP-string

<script> const text2 = <?php echo json_encode($kallory, JSON_PRETTY_PRINT); ?>; let index2 = 0; function type() { document.getElementById(‘typewriter’).innerText += text2[index2]; index2++; if (index2 < text2.length) { setTimeout(type, 30); } } type(); </script> And my $kallory-string from PHP $kallory = ‘Word1xa0Word2xa0Word3xa0Word4′; And the output: Word1xa0Word2xa0Word3xa0Word4 I have tried with xa0,   and also just ‘Word1 Word2 Word3’. […]

stringify() object value using with JSON

<script> var Dan = new Object() Dan.height = 1.85 Dan.age = 41 Dan.eyeColor = “blue” // method ONE alert(JSON.stringify(Dan)) // method TWO worked too as below // alert(JSON.stringify(“Dan”)) </script> Which one is better and why? Appreciated. I tried the code above on my localhost. javascript json