Open In App

ASP Exists Method

Last Updated : 22 Mar, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

The ASP Exists Method is used to return a Boolean value that returns true if the specified key exists, otherwise it returns false.

Syntax:

DictionaryObject.Exists(key)

Parameters: This method has a single parameter as mentioned above and discussed below:

  • Key: It specifies the name of the key value to be searched in the dictionary.

Example :The below code demonstrates the ASP Dictionary.Exists Method.

ASP




<%
dim dict
  
'Create a new dictionary
set dict=Server.CreateObject("Scripting.Dictionary")
  
'Add values to the dictionary
dict.Add "g","geeks"
dict.Add "p","placements"
dict.Add "c","competitive"
  
'Check if the key exists in the dictionary
if dict.Exists("g")=true then
  Response.Write("The 'g' key exists in the dictionary")
else
  Response.Write("The 'g' key does not exist in the dictionary")
end if
  
Response.Write("<br>")
  
'Check for another key in the dictionary
if dict.Exists("m")=true then
  Response.Write("The 'm' key exists in the dictionary")
else
  Response.Write("The 'm' key does not exist in the dictionary")
end if
  
set dict=nothing
%>


Output:

The 'g' key exists in the dictionary
The 'm' key does not exist in the dictionary 

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads