Use of Array.find() Method in JavaScript

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

306 Views

Array.find()Array.find() is used to return value of first element in the array that satisfies provided testing condition(user given condition).If the provided testing condition fails then array.find() returns undefined.In the following example array.find() checks whether the price elements in array are more than the given testing price(12000). If the provided testing condition true then first value that passed the test will be executed, if not undefined will be executed. ExampleLive Demo    var price = [3000, 21000, 28000, 20000, 15500];    function checkCost(cost) {       return cost >= 12000;    }    document.getElementById("price").innerHTML = price.find(checkCost); Output21000

Create JLabel with Image Icon in Java

Smita Kapse
Updated on 30-Jul-2019 22:30:26

6K+ Views

Let us create a label with image icon −JLabel label = new JLabel("SUBJECT "); label.setIcon(new ImageIcon("E:ew.png"));Now, create another component −JTextArea text = new JTextArea(); text.setText("Add subject here...");Align the components with GridBagLayout −panel.setLayout(new GridBagLayout());The following is an example to center a label with an image icon −Examplepackage my; import java.awt.GridBagLayout; import javax.swing.BorderFactory; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.WindowConstants; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame("Demo Frame");       JPanel panel = new JPanel();       JLabel label = new JLabel("SUBJECT "); ... Read More

Foreach in C++ and Java

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

167 Views

In C++ and Java, there are another type of loop called foreach loop. This is not present in C. This loop has introduced in C++11 and Java JDK 1.5.0. The advantage of this loop is that, it can access the elements very quickly without performing initialization, testing and increment/decrement. This loop is used to access every element in one array or some containers. This loop is known as foreach but to denote this loop we have to use ‘for’ keyword. The syntax is different than normal for and foreach.for(datatype item : Array) { }Let us see some examples of foreach ... Read More

What is Thin Ethernet?

Moumita
Updated on 30-Jul-2019 22:30:26

2K+ Views

Thin Ethernet, popularly known as cheapernet or thinnet, is among the family of Ethernet standards that uses thinner coaxial cable as a transmission media. It is technically known as 10-BASE-2. Here, 10 is the maximum throughput, i.e. 10 Mbps, BASE denoted use of baseband transmission, and 2 refers to the maximum segment length of about 200 metres (precisely 185 metres).This type of cabling allows a maximum of 30 stations to be connected to it by BNC connectors with 50 centimetres minimum gap between subsequent stations.Features of Cable and NetworkThe salient features of 10-BASE-2 Ethernet cabling are −10-BASE-2 use RG-58 A/U ... Read More

Importance of Union Method in JavaScript

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

1K+ Views

_.union()_.Union() method belongs to underscore.js a library of javascript. The _.union() function is used to take n number of arrays and return a new array with the unique terms in all those arrays (union of all array). It scrutinizes each and every value of the arrays and pushes out unique values into another array.syntax_.union( array1, array2, .... );ExampleIn the following example, _.union() is used to get an array of unique elements.Live Demo document.write(_.union([1, 2, 9, 40], ... Read More

HTML DOM Input Email Object

AmitDiwan
Updated on 30-Jul-2019 22:30:26

141 Views

The HTML DOM Input Email Object represents an input HTML element with type email.SyntaxFollowing is the syntax −Creating an with type emailvar emailObject = document.createElement(“input”); emailObject.type = “email”;AttributesHere, “emailObject” can have the following attributes −AttributesDescriptionautocompleteIt provides suggestions based on previously typed text, if set to ‘ON’autofocusIf set to true the email field is focused upon initial page load.defaultValueIt sets/returns the default value of an email fielddisabledIt defines if an email field is disabled/enabledformIt returns a reference of enclosing form that contains the email fieldmaxLengthIt returns/sets the value of maxLength attribute of an email fieldmultipleIt returns/sets if an email field ... Read More

Print Matrix in Antispiral Form

Sunidhi Bansal
Updated on 30-Jul-2019 22:30:26

431 Views

Given a 2d array of n*n and the task is to find the antispiral arrangement of the given matrixInput : arr[4][4]={1,2,3,4,    5,6,7,8,    9,10,11,12    13,14,15,16} Output: 10 11 7 6 5 9 13 14 15 16 12 8 4 3 2 1For this, stack can be used where the transpose of a matrix can be pushed inside stack and poped reverselyAlgorithmSTART STEP 1 -> declare stack vector element as stk and variables as int r=4, c=4, i, j, rs=0 and cs=0 Step 2 -> store matrix elements in 2-3 array Step 3 -> Loop For i=0 and o

Create Users in MongoDB Using a Script

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

321 Views

You can use createUser() method for this. Following is the syntax −db.createUser(    {       user: "yourUserName",       pwd: "yourPassword",       roles: [ { role: "read", db: "yourDatabaseName" } ]    } );Let us create a user in MongoDB. Here, we are using database ‘test’ −> db.createUser( ...    { ...       user: "David", ...       pwd: "David123456", ...       roles: [ { role: "read", db: "test" } ] ...    } ... );This will produce the following output −Successfully added user: {    "user" : "David",    "roles" : [       {          "role" : "read",          "db" : "test"       }    ] }

Play Android Notification Sound

Arjun Thakur
Updated on 30-Jul-2019 22:30:26

556 Views

This example demonstrate about How to play ringtone/alarm/notification sound in Android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.     Step 3 − Add the following code to src/MainActivity.javapackage app.tutorialspoint.com.notifyme; import android.app.NotificationManager; import android.content.Context; import android.media.MediaPlayer; import android.media.RingtoneManager; import android.net.Uri; import android.support.v4.app.NotificationCompat; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import java.util.Objects; public class MainActivity extends AppCompatActivity {    private final static String default_notification_channel_id = "default";    @Override    protected void onCreate (Bundle ... Read More

Sum Every Field in a Sub-Document of MongoDB

Smita Kapse
Updated on 30-Jul-2019 22:30:26

424 Views

To sum every field in a sub document, use aggregate framework. Let us first create a collection with documents −> db.sumEveryFieldDemo.insertOne( ...    { ...       "_id":101, ...       "PlayerDetails": [ ...          {"PlayerName":"John", "PlayerScore":1000}, ...          {"PlayerName":"Carol", "PlayerScore":2000}, ...          {"PlayerName":"Sam", "PlayerScore":3000} ...       ] ...    } ... ); { "acknowledged" : true,  "insertedId" : 101 }Following is the query to display all documents from a collection with the help of find() method −> db.sumEveryFieldDemo.find().pretty();This will produce the following output −{    "_id" : 101,    "PlayerDetails" : [       {          "PlayerName" : "John",   ... Read More

Advertisements