“JS Substring” Kode Jawaban

JS Substring

// the substring method returns a string out of another string

const str = 'Mozilla';

console.log(str.substring(1, 3));
// expected output: "oz"

console.log(str.substring(2));
// expected output: "zilla"
mikelikestocode

Substring JavaScript

var str = "Hello world!";
var res = str.substring(1, 4); //ell
Sleepy Swiftlet

JavaScript cara mendapatkan huruf tengah dari suatu string

 function extractMiddle(str) {

        var position;
        var length;

        if(str.length % 2 == 1) {
            position = str.length / 2;
            length = 1;
        } else {
            position = str.length / 2 - 1;
            length = 2;
        }

        return str.substring(position, position + length)
    }

    console.log(extractMiddle("handbananna"));
Famous Ferret

Substring

const str = 'Mozilla';

console.log(str.substring(1, 3));
// expected output: "oz"

console.log(str.substring(2));
// expected output: "zilla"
Prickly Pony

substr () javascript

const str = 'substr';

console.log(str.substr(1, 2)); // (1, 2): ub
console.log(str.substr(1)); // (1): ubstr

/* Percorrendo de trás para frente */
console.log(str.substr(-3, 2)); // (-3, 2): st
console.log(str.substr(-3)); // (-3): str
Cipriano98

Substring di JavaScript menggunakan substring

const str = "Learning to code";

// substring between index 2 and index 5
console.log(str.substring(2, 5));
// substring between index 0 and index 4
console.log(str.substring(0, 4));

// using substring() method without endIndex
console.log(str.substring(2));
console.log(str.substring(5));
Clumsy Caiman

Jawaban yang mirip dengan “JS Substring”

Pertanyaan yang mirip dengan “JS Substring”

Lebih banyak jawaban terkait untuk “JS Substring” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya