/* Splitting a string using a specific delimiter */
const sentence = "JavaScript is a client-side scripting language.";
const wordsArray = sentence.split(" "); // Split the string into an array based on spaces

console.log(wordsArray);
// Output: ["JavaScript", "is", "a", "client-side", "scripting", "language."]


/* Splitting a string using a regular expression */
const str = "This is an example.";
const words = str.split(/\s+/); // Split the string into an array using a whitespace regular expression (/\s+/)

console.log(words[0]); // Output: "This"
console.log(words[1]); // Output: "is"
console.log(words[2]); // Output: "an"
console.log(words[3]); // Output: "example."


/* Parsing a URL */
const url = "https://www.example.com/path/to/file.html?param=value";

const parts = url.split("?"); // Split the URL into an array using "?" as the delimiter

console.log(parts[0]); // Output: "https://www.example.com/path/to/file.html"
console.log(parts[1]); // Output: "param=value"
str.split()
str.split(separator)
str.split(separator, limit)
const sentence = "Hello. Welcome!";
const wordsArray = sentence.split();

console.log(wordsArray);
// Output: ["Hello. Welcome!"]
const sentence = "Hello. Welcome!";
const wordsArray = sentence.split("");

console.log(wordsArray);
// Output: ["H", "e", "l", "l", "o", ".", " ", "W", "e", "l", "c", "o", "m", "e", "!"]
const sentence = ",Hello. Welcome!";

// Use "," as the separator at the beginning of the string
const wordsArray = sentence.split(",");

// The returned array starts with an empty string ("")
console.log(wordsArray);
// Output: ["", "Hello. Welcome!"]
const sentence = "Hello. Welcome!,";

// Use "," as the separator at the end of the string
const wordsArray = sentence.split(",");

// The returned array ends with an empty string ("")
console.log(wordsArray);
// Output: ["Hello. Welcome!", ""]
const sentence = ",Hello. Welcome!,";

// Use "," as the separator at both the beginning and end of the string
const wordsArray = sentence.split(",");

// The returned array starts and ends with an empty string ("")
console.log(wordsArray);
// Output: ["", "Hello. Welcome!", ""]
const sentence = "H";
const wordsArray = sentence.split("H");

console.log(wordsArray);
// Output: ["", ""]
const sentence = "";
const wordsArray = sentence.split("");

console.log(wordsArray);
// Output: []
const str = "This is an example.";
const words = str.split(" ");

console.log(words);
// Output: ["This", "is", "an", "example."]
const time = "02:30:45";
const timeParts = time.split(":");
const hours = timeParts[0];

console.log("Hours:", hours);
// Output: "Hours: 02"
const filePath = "/path/to/file.txt";

/* Split by "/" and return the last element of the array using the pop() function */
const fileName = filePath.split("/").pop();

console.log(fileName);
// Output: "file.txt"
const email = "user@example.com";
const parts = email.split("@");

const domain = parts[1];

console.log(domain);
// Output: "example.com"