Author: Arpit Mandliya
- 23 December
Get Index of Max Value in Array in JavaScript
Using indexOf() with Math.max() Method To get an index of the max value in a JavaScript array: Use the Math.max() function to find the maximum number from the given numbers. Here, we passed an array and used the spread operator (...) to expand the array into individual elements. Use the .indexOf() function to get the […]
- 23 December
Remove All Non-numeric Characters in Pandas
1. Introduction One of the common tasks that pandas users face is to remove all non-numeric characters from a column or a dataframe. Non-numeric characters are any characters that are not digits, such as letters, punctuation, symbols, or whitespace. Removing non-numeric characters can help to clean the data and prepare it for further processing or […]
- 23 December
How To Do Line Continuation in Python
Using Backslash (\) Operator We can use \ operator for line continuation in string and number expression as follows. Line Continuation in String To do line continuation in Python Strings: Use the backslash operator to do line continuation for writing strings in Python. [crayon-676cb470696bd353069130/] [crayon-676cb470696c0887897337/] A backslash (\) is an explicit line break operator in […]
- 22 December
Update Key with New Value in JavaScript
Using Bracket Notation We can use bracket notation to update the key with the new value in Python. Update Single Key with New Value To update a single key with a new value, use bracket notation to read it and update it with a new value. [crayon-676cb470697e5600068923/] [crayon-676cb470697e8624809376/] Bracket notation in JavaScript is a way […]
- 21 December
Format Phone Number in JavaScript
Using match() Method We use the match() method to format a phone number in JavaScript. Format Without Country Code To format the phone number without country code: Use the replace() method with a regular expression /\D/g to remove non-numeric elements from the phone number. Use the match() method with a regular expression to match and […]
- 21 December
Save Object to File in Python
1. Introduction In Python, one often encounters the need to save complex objects, like instances of a class, to a file for purposes such as data persistence. Let’s take a Student class as an example, which includes attributes like name, email, age, city, courses, and address. The goal is to efficiently serialize this object into […]
- 21 December
Remove Word from String in JavaScript
Using replace() Method We can use the replace() method to remove a word or words from a string in JavaScript. Remove a Single Occurrence of a Word To remove a single occurrence of a word from a string, use the replace() method to replace the word in the string with an empty string. [crayon-676cb4706a732341124777/] [crayon-676cb4706a736017354284/] […]
- 18 December
Write Array to CSV in JavaScript
Using toString() method To write array to CSV in JavaScript: Declare an array with some elements in it. Use the toString() method. This method will convert the array into the CSV(Comma-Separated Value). Finally, console the value to see the result. Follow the below program: [crayon-676cb4706a826504660289/] Output: [crayon-676cb4706a829323989339/] Using join() method To write array to CSV […]
- 18 December
Write Binary File in Python
Use bytearray() Function To write a binary file in Python: Use the bytearray() function to convert the list of bytes to a bytearray type object. Use a with clause with open() the method in write binary mode(wb) Use write() method to write the byte_array to the file. [crayon-676cb4706a935147156326/] [crayon-676cb4706a938996547097/] We created a byte_list using a […]