' metodo slice () estrae una parte di una stringa e restituisce le parti estratte in una nuova stringa https://www.w3schools.com/js/tryit.asp?filename=tryjs_string_slice <!DOCTYPE html> <html> <body> <h2>JavaScript String Methods</h2> <p>The slice() method extract a part of a string and returns the extracted parts in a new string:</p> <p id="demo"></p> <script> var str = "Apple, Banana, Kiwi"; var res = str.slice(7,13); document.getElementById("demo").innerHTML = res; </script> </body> </html> ' oppure con dati in negativo a partire dalla fine andando indietro https://www.w3schools.com/js/tryit.asp?filename=tryjs_string_slice_negative <!DOCTYPE html> <html> <body> <h2>JavaScript String Methods</h2> <p>The slice() method extract a part of a string and returns the extracted parts in a new string:</p> <p id="demo"></p> <script> var str = "Apple, Banana, Kiwi"; var res = str.slice(-12,-6); document.getElementById("demo").innerHTML = res; </script> </body> </html> ' oppure Se ometti il ??secondo parametro, il metodo troncera' il resto della stringa: https://www.w3schools.com/js/tryit.asp?filename=tryjs_string_slice_rest <!DOCTYPE html> <html> <body> <h2>JavaScript String Methods</h2> <p>The slice() method extract a part of a string and returns the extracted parts in a new string:</p> <p id="demo"></p> <script> var str = "Apple, Banana, Kiwi"; var res = str.slice(7); document.getElementById("demo").innerHTML = res; </script> </body> </html> |