The scrollX property in JavaScript works the same as pageXoffset property. If you want to get the pixels the document scrolled to from the upper left corner of the window, then use the scrollX property for horizontal pixels.ExampleYou can try to run the following code to learn how to work with scrollX property in JavaScript. div { background-color: yellow; height: 1500px; width: 1500px; } function scrollFunc() { window.scrollBy(200, 200); alert("Horizontal: " + window.scrollX); } Scroll
Use the document.images property in JavaScript to get the number of tags in a document.ExampleYou can try to run the following code to implement document.images property in JavaScript.Live Demo JavaScript Example TutorialsPoint Tutorials var num = document.images.length; document.write("How many images? "+num);
While dalign with lists, we may come across a situation where we have to process a string and get its individual characters for further processing. In this article we will see various ways to do that.With list comprehensionWe design a for loop to go through each element of the list and another loop inside this to pick each character from the element which is a string.Example Live DemolistA = ['Mon', 'd', 'ay'] # Given lists print("Given list : ", listA) # Get characters res = [i for ele in listA for i in ele] # Result print("List of characters: ", res)OutputRunning ... Read More
For data manipulation in python we may come across situation to convert a dictionary object into a string object. This can be achieved in the following ways.with str()In this straight forward method we simple apply the str() by passing the dictionary object as a parameter. We can check the type of the objects using the type() before and after conversion.Example Live DemoDictA = {"Mon": "2 pm", "Wed": "9 am", "Fri": "11 am"} print("Given dictionary : ", DictA) print("Type : ", type(DictA)) # using str res = str(DictA) # Print result print("Result as string:", res) print("Type of Result: ", type(res))OutputRunning the above ... Read More
Use the document.embeds property in JavaScript to get the number of tags in a document.ExampleYou can try to run the following code to implement document.embeds property in JavaScript.Live Demo JavaScript Example var num = document.embeds.length; document.write("How many embed tags: "+num);
To return a random number between 0 and 199, use the JavaScript Math.random() and Math.floor() method.ExampleYou can try to run the following code to return a random number in JavaScript. document.write(Math.floor(Math.random() * 200));
As part of data manipulation, we will come across the need to have a single case for all the letters in a string. In this article we will see how to take a list which has string elements with mixed cases. We then apply some python functions to convert them all to a single case.With lower()The lower function is a string function that can convert the entire string to lower case. So we use lambda and map to apply the lower function to each of the elements in the list.Example Live DemolistA = ['MoN', 'TuE', 'FRI'] # Given list print("Given list ... Read More
The byte string in python is a string presentd with letter b prefixed on it. In this article we will see how to convert a dictionary with the bytecode string into a normal dictionary which represents only strings.With decode and asciiPython string method decode() decodes the string using the codec registered for encoding. It defaults to the default string encoding. We use it to convert the bytecode value into normal asci values by supplying ascii as the parameter to the decode function.Example Live Demobstring = {b'day': b'Tue', b'time': b'2 pm', b'subject': b'Graphs'} print(bstring) # Use decode stringA = {y.decode('ascii'): bstring.get(y).decode('ascii') for ... Read More
As python handles various data types, we will come across a situation where a list will appear in form of a string. In this article we will see how to convert a string into a list.With strip and splitWe first apply the strip method to remove the square brackets and then apply the split function. The split function with a comma as its parameter create the list from the string.Example Live DemostringA = "[Mon, 2, Tue, 5, ]" # Given string print("Given string", stringA) print(type(stringA)) # String to list res = stringA.strip('][').split(', ') # Result and its type print("final list", res) ... Read More
Sometimes we may have a list whose elements are integers. There may be a need to combine all these elements and create a single integer out of it. In this article we will explore the ways to do that.With joinThe join method can Join all items in a tuple into a string. So we will use it to join each element of the list by iterating through them through a for loop.Example Live DemolistA = [22, 11, 34] # Given list print("Given list A: ", listA) # Use res = int("".join([str(i) for i in listA])) # Result print("The integer is : ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP