To get value of any attribute from XML data, use attr() in JavaScript. Following is the code −Example Live Demo Document var yourXMLDetails = '' +'' +'' +'' console.log("Game Details==="+$(yourXMLDetails).attr("details")); To run the above program, save the file name “anyName.html(index.html)” and right click on the file. Select the option “Open with Live Server” in VS Code editor.OutputThis will produce the following output −
Let’s say the following is our object −var customerDetails= [ { customerId:101, customerName:"John" }, { customerId:102, customerName:"David" }, { customerId:103, customerName:"Mike" }, { customerId:104, customerName:"Bob" } ]Use for loop with the following condition to display only odd CustomerID records −for(var index=0;index
You can use the concept of createHTMLDocument(). Following is the code −Example Document const htmlDocument = document.implementation.createHTMLDocument(); const customURL = htmlDocument.createElement( 'base' ); customURL.href = "https://www.tutorialspoint.com/java/index.htm"; htmlDocument.head.append( customURL ); console.log("Base URL="+customURL.href); const modifiedURL = htmlDocument.createElement("a"); modifiedURL.href = "../java/java_questions_answers.html"; htmlDocument.body.append( modifiedURL ); console.log("After Modifying URL="+ modifiedURL.href ); To run the above program, save the file name “anyName.html(index.html)” and right click on the file. Select the option “Open with Live Server” in VS Code editor.OutputThis will produce the following output: on ... Read More
To select all elements with “data-“ attribute, use document.querySelectorAll(“”). Following is the code −Example Live Demo Document var result=document.querySelectorAll('[data-sentence]'); for (var index in result){ if (result.hasOwnProperty(index)){ console.log(result[index].getAttribute('data-sentence')); } } To run the above program, save the file name “anyName.html(index.html)” and right click on the file. Select the option “Open with Live Server” in VS Code editor.OutputThis will produce the following output −
To match multiple occurrences in a string, use regular expressions. Following is the code −Examplefunction checkMultipleOccurrences(sentence) { var matchExpression = /(JavaScript?[^\s]+)|(typescript?[^\s]+)/g; return sentence.match(matchExpression); } var sentence="This is my first JavaScript Program which is the subset of typescript"; console.log(sentence); console.log(checkMultipleOccurrences(sentence));To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo70.js.OutputThis will produce the following output −PS C:\Users\Amit\JavaScript-code> node demo70.js This is my first JavaScript Program which is the subset of typescript [ 'JavaScript', 'typescript' ]
When we have repeated elements in an R vector and the vector size is large then we might want to know the distinct values in that vector. This will help us to understand the unique values we have in our vector, so that we can create the appropriate chart and perform the appropriate analysis using that vector. This can be done by using length function with unique.Examples Live Demo> x1 x1Output[1] 2 5 5 3 2 4 3 3 1 4 5 4 5 3 3 1 1 2 5 1 3 2 4 1 3 1 5 4 2 5 ... Read More
To find the row and column indices of values in a matrix, we cannot simply use which function because it returns the index based on sequence of the numbers in the matrix. For example, if we have a matrix M as below −1 2 3 4 1 6 7 8 1Now if we try to find the index using which(M==1) then it will return 1 5 9Because 1 is placed at 1, 5 and 9.Hence, we need to use arr.ind = TRUE so that the matrix can be read as an array by which function.ExampleConsider the below matrix − Live Demo> ... Read More
Sometimes we just want to extract the values of a data column based on initial and ending values of a column that has strings or sometimes the values of a column that has strings are recorded with some extra characters and we want to extract those values. For this purpose, we can use negation of grepl with single square brackets.ExampleConsider the below data frame −> x2 df2 head(df2, 20)Outputx2 1 Alabama 2 Alaska 3 American Samoa 4 Arizona 5 Arkansas 6 California 7 Colorado 8 Connecticut 9 Delaware 10 District of Columbia 11 Florida 12 Georgia 13 Guam 14 Hawaii ... Read More
A footnote is generally used to give references to a document, text or image and it is called citation. It helps the reader or viewer to check out the original source using the new text or image is generated. If we want to give citation to a plot in R using ggplot2 package then we can add labs that has caption option to add the footnotes.ExampleConsider the below data frame − Live Demo> set.seed(1) > x y df dfOutput x y 1 0.8735462 4.0117812 2 1.6836433 2.8898432 3 0.6643714 1.8787594 4 3.0952808 0.2853001 5 1.8295078 3.6249309 ... Read More
Sometimes we have vectors with NA values, also there might be a situation that one of vector having an NA at a position and the other vector has the numerical values at the same position. For example, 1, 2, NA and 1, 2, 3. In this case, we might want to combine these two vectors to make a single vector. This can be done by using coalesce function of dplyr package.Example> library(dplyr) > x1 x1Output[1] NA 4 NA 1 2 NA 4 1 4 1 2 3 1 4 2 2 NA 2 2 1Example Live Demo> y1 y1Output[1] 1 2 ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP